垃圾数据“无法调用方法”hasOwnProperty“未定义” [英] Ember-data "Cannot call method 'hasOwnProperty' of undefined"
问题描述
我有以下Ember.js模型:
I have the following Ember.js model:
Filters.Milestone = DS.Model.extend({
id: DS.attr('string'),
name: DS.attr('string')
});
在我的app.js中,我有以下模型设置(在模型之前加载):
In my app.js I have the following settings for the model (loaded prior to the model):
Filters.MilestoneSerializer = DS.RESTSerializer.extend();
Filters.MilestoneAdapter = DS.RESTAdapter.extend({
namespace: "ember"
});
加载页面时,会完成对里程碑列表的AJAX调用。返回以下JSON:
When loading the page, an AJAX call to the milestones list is done. The following JSON is returned:
{
"milestones": [
{
"id": "1",
"name": "Test Milestone #1"
}
]
}
加载JSON时,会返回以下错误:
When the JSON is loaded, the following error is returned:
TypeError: Cannot call method 'hasOwnProperty' of undefined
at e (http://sandbox.local/ember/js/libs/ember-data.js:8:30934)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:8:31181)
at ComputedPropertyPrototype.set (http://sandbox.local/ember/js/libs/ember-1.4.0.js:4903:18)
at new Class (http://sandbox.local/ember/js/libs/ember-1.4.0.js:12652:18)
at Function.Mixin.create.create (http://sandbox.local/ember/js/libs/ember-1.4.0.js:13104:12)
at Ember.Object.extend.buildRecord (http://sandbox.local/ember/js/libs/ember-data.js:10:2880)
at Ember.Object.extend.recordForId (http://sandbox.local/ember/js/libs/ember-data.js:9:31214)
at Ember.Object.extend._load (http://sandbox.local/ember/js/libs/ember-data.js:10:2048)
at Ember.Object.extend.push (http://sandbox.local/ember/js/libs/ember-data.js:10:2450)
at null.<anonymous> (http://sandbox.local/ember/js/libs/ember-data.js:10:2701)
$ b $我做错了什么?我尝试遵循与 https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/adapter/rest_adapter_test.js#L465 。如果我重命名里程碑键,它说没有找到新钥匙的模型,所以一定要正确: - )
What am I doing wrong? I have tried following the same structure as https://github.com/emberjs/data/blob/master/packages/ember-data/tests/integration/adapter/rest_adapter_test.js#L465. If I rename the milestones key it says that no model could be found for the new key, so something must be right :-)
提前感谢
我使用的路由如下:
Filters.FiltersRoute = Ember.Route.extend({
model: function() {
return this.store.find('milestone')
}
});
如果 this.store.find('milestone')
不叫错误不发生。另外,如果我使用 FixtureAdapter
而不是 RESTAdapter
,错误仍然发生。所以似乎这可能与模型有关,而不是数据源。
If this.store.find('milestone')
is not called the error doesn't occur. Also, if I use the FixtureAdapter
instead of the RESTAdapter
, the error still occurs. So it seems that this might be related to the model, not the data source.
推荐答案
问题是由code> id 属性。显然这不应该是模型的一部分。
The problem was caused by the id
attribute in the model. Apparently this should not be part of the model.
这篇关于垃圾数据“无法调用方法”hasOwnProperty“未定义”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!