javascript - 处理路线时出错:导致 str 未定义 DECAMELIZE_CACHE (EmberJS)
问题描述
我正在尝试使用 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
我试图用谷歌搜索解决方案,并检查堆栈溢出是否有任何与此相关的内容,但无济于事。似乎是什么问题?我什至记录了数据,它正确显示了有效负载,但不知何故,错误随即出现。
适配器/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'
}
})
});
适配器/lead.js
import generic from './generic'
export default generic.extend({
pathForType(){
return 'Leads';
}
});
模型/lead.js
import DS from 'ember-data';
export default DS.Model.extend({
records: DS.hasMany('record')
});
模型/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')
});
路线/leads.js
import Route from '@ember/routing/route';
export default Route.extend({
model(){
return this.store.findAll('lead');
}
});
序列化程序/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);
}
});
非常感谢您对我的包容和您的提前帮助!
解决方案
没关系,我不得不将数据更改为payload = payload.records
serializers /lead.js,似乎我的有效负载包含多个导致问题的嵌套对象
推荐阅读
- java - 使用监听器和 DoubleProperty 获取零钱
- python-3.x - Pyomo:值错误:未初始化的 NumericValue 对象 fo[1,1_C1] 没有值
- php - Cpanel Godaddy 要求打开失败
- python - 给定索引位置的 Pandas concat 数据框
- python - python中在另一个类中创建一个类的正确方法?
- c# - 仅当其非 null 时才在布尔值中分配不可为空的值
- java - 检查矩阵内的总和并递归地将路径保留在第二个数组上
- powerpoint - PowerPoint 插件关闭事件
- python - 从 HTTP 响应中获取 JSON?
- python-3.x - python multiprocessing .get() 永远不会结束