我正在尝试使用EmberJS将有效负载中的数据存储到模型中,以便以后可以在表中显示它。但是,当我运行应用程序时,这是我得到的错误:
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
我尝试过搜索解决方案,并检查堆栈溢出是否与此有关,但无济于事。似乎是什么问题?我什至记录了数据,它可以正确显示有效负载,但是在出现错误后立即以某种方式显示出来。
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);
}
});
非常感谢您与我保持联系,并提前得到您的帮助!
答案 0 :(得分:0)
没关系,我不得不在 serializers / lead.js 中将数据更改为payload = payload.records
,似乎我的有效载荷包含多个嵌套对象,这导致了问题