店铺:
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
显示正确的值?