0

店铺:

App.Store = DS.Store.extend({
    revision: 12,
    adapter: DS.BasicAdapter.create()
});

模型:

var Profiles = DS.Model.extend({
    displayName: DS.attr('string'),
    profileName: DS.attr('string')
}),
User = DS.Model.extend({
    email: DS.attr('string'),
    phone: DS.attr('string'),
    profiles: DS.hasMany(Profiles, {embedded: true})
});

模型的 JSON 数据:

{
    "email": "some email",
    "phone": "some phone number",
    "profiles": [
        {
            "displayName": "some name",
            "profileName": "some name"
        },
        {
            "displayName": "some name",
            "profileName": "some name"
        }
    ]
}

在模板中:

{{#if model.isLoaded}}
    email: {{model.email}} // displayed
    {{model.profiles.length}} // number of objects in array is displayed

    {{#each model.profiles}}
        // this line generates error Uncaught TypeError: Cannot call method
           '_create' of undefined ember-data.js:2560
    {{/each}}
{{/if}}

知道为什么这条线会产生错误吗?特别是如果model.profiles.length显示正确的值?

4

1 回答 1

0

起初,您用于嵌入Profiles用户的语法不再相关。请检查此答案以了解设置此选项的正确方法。

于 2013-05-02T15:27:31.743 回答