I am trying to store data from the payload into a model using EmberJS, so that I can later display it in the table. However, when I run the application this is the error i get:
Error while processing route: leads str is undefined DECAMELIZE_CACHE<@http://localhost:4200/assets/vendor.js:17268:9
get@http://localhost:4200/assets/vendor.js:53750:39
decamelize@http://localhost:4200/assets/vendor.js:17361:16
STRING_DASHERIZE_CACHE<@http://localhost:4200/assets/vendor.js:17226:16
get@http://localhost:4200/assets/vendor.js:53750:39
dasherize@http://localhost:4200/assets/vendor.js:17380:16
normalizeModelName@http://localhost:4200/assets/vendor.js:64782:12
modelNameFromPayloadKey@http://localhost:4200/assets/vendor.js:80398:48
_extractType@http://localhost:4200/assets/vendor.js:80384:14
normalize@http://localhost:4200/assets/vendor.js:80425:15
_normalizePolymorphicRecord@http://localhost:4200/assets/vendor.js:82138:14
_normalizeArray/<@http://localhost:4200/assets/vendor.js:82112:34
_normalizeArray@http://localhost:4200/assets/vendor.js:82111:34
_normalizeResponse@http://localhost:4200/assets/vendor.js:82238:34
normalizeArrayResponse@http://localhost:4200/assets/vendor.js:81015:14
normalizeFindAllResponse@http://localhost:4200/assets/vendor.js:80875:14
normalizeResponse@http://localhost:4200/assets/vendor.js:80818:18
normalizeResponse@http://localhost:4200/assets/ember-sugar.js:347:14
superWrapper@http://localhost:4200/assets/vendor.js:53473:23
normalizeResponseHelper@http://localhost:4200/assets/vendor.js:70266:30
_findAll/<@http://localhost:4200/assets/vendor.js:70581:21
tryCatcher@http://localhost:4200/assets/vendor.js:59477:14
invokeCallback@http://localhost:4200/assets/vendor.js:59649:15
publish@http://localhost:4200/assets/vendor.js:59635:9
@http://localhost:4200/assets/vendor.js:51876:16
invoke@http://localhost:4200/assets/vendor.js:27556:17
flush@http://localhost:4200/assets/vendor.js:27476:25
flush@http://localhost:4200/assets/vendor.js:27635:25
_end@http://localhost:4200/assets/vendor.js:28057:26
end@http://localhost:4200/assets/vendor.js:27822:13
_run@http://localhost:4200/assets/vendor.js:28102:21
_join@http://localhost:4200/assets/vendor.js:28078:24
join@http://localhost:4200/assets/vendor.js:27876:20
join@http://localhost:4200/assets/vendor.js:16517:12
ajax/</hash.success@http://localhost:4200/assets/vendor.js:79042:11
fire@http://localhost:4200/assets/vendor.js:3609:11
fireWith@http://localhost:4200/assets/vendor.js:3739:7
done@http://localhost:4200/assets/vendor.js:9646:5
callback/<@http://localhost:4200/assets/vendor.js:9889:9
I have tried to google the solution as well as check if there is anything related to this on stack overflow, but to no avail. What seems to be the problem? I have even logged the data and it shows the payload correctly but somehow right after that the error pops up.
adapters/generic.js
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: "http://localhost/SugarPro-Full-8.0.0",
namespace: "rest/v10",
headers: Ember.computed(function() {
return {
'oauth-token': sessionStorage.getItem('token'),
'Content-Type': 'application/json'
}
})
});
adapters/lead.js
import generic from './generic'
export default generic.extend({
pathForType(){
return 'Leads';
}
});
models/lead.js
import DS from 'ember-data';
export default DS.Model.extend({
records: DS.hasMany('record')
});
models/record.js
import DS from 'ember-data';
export default DS.Model.extend({
name: DS.attr('string'),
status: DS.attr('string'),
account_name: DS.attr('string'),
phone_work: DS.attr('string'),
date_entered: DS.attr('string'),
date_modified: DS.attr('string')
});
routes/leads.js
import Route from '@ember/routing/route';
export default Route.extend({
model(){
return this.store.findAll('lead');
}
});
serializers/lead.js
import DS from 'ember-data';
import Ember from 'ember';
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
records: { embedded: 'always' }
},
normalizeResponse(store, primaryModelClass, payload, id, requestType){
payload = {records:payload}
console.log(payload);
return this._super(store, primaryModelClass, payload, id, requestType);
}
});
Many thanks for bearing with me and for your help in advance!
Aucun commentaire:
Enregistrer un commentaire