最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ember-data "Cannot call method 'hasOwnProperty' of undefined" - Stack Overflow

programmeradmin3浏览0评论

I have the following Ember.js model:

Filters.Milestone = DS.Model.extend({
    id: DS.attr('string'),
    name: DS.attr('string')
});

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"
});

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"
        }
    ]
}

When the JSON is loaded, the following error is returned:

TypeError: Cannot call method 'hasOwnProperty' of undefined
    at e (/ember/js/libs/ember-data.js:8:30934)
    at null.<anonymous> (/ember/js/libs/ember-data.js:8:31181)
    at ComputedPropertyPrototype.set (/ember/js/libs/ember-1.4.0.js:4903:18)
    at new Class (/ember/js/libs/ember-1.4.0.js:12652:18)
    at Function.Mixin.create.create (/ember/js/libs/ember-1.4.0.js:13104:12)
    at Ember.Object.extend.buildRecord (/ember/js/libs/ember-data.js:10:2880)
    at Ember.Object.extend.recordForId (/ember/js/libs/ember-data.js:9:31214)
    at Ember.Object.extend._load (/ember/js/libs/ember-data.js:10:2048)
    at Ember.Object.extend.push (/ember/js/libs/ember-data.js:10:2450)
    at null.<anonymous> (/ember/js/libs/ember-data.js:10:2701)

What am I doing wrong? I have tried following the same structure as .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 :-)

Thanks in advance.

Edit

The route that I use is the following:

Filters.FiltersRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('milestone')
    }
});

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.

I have the following Ember.js model:

Filters.Milestone = DS.Model.extend({
    id: DS.attr('string'),
    name: DS.attr('string')
});

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"
});

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"
        }
    ]
}

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)

What am I doing wrong? I have tried following the same structure as https://github./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 :-)

Thanks in advance.

Edit

The route that I use is the following:

Filters.FiltersRoute = Ember.Route.extend({
    model: function() {
        return this.store.find('milestone')
    }
});

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.

Share Improve this question edited Feb 24, 2014 at 15:02 fiskah asked Feb 24, 2014 at 14:39 fiskahfiskah 5,9126 gold badges38 silver badges58 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

The problem was caused by the id attribute in the model. Apparently this should not be part of the model.

发布评论

评论列表(0)

  1. 暂无评论