我正在尝试将固定装置加载到我的具有嵌入式记录的应用程序中。
从服务器加载数据(使用DS.RESTAdapter
)有效,但当我尝试通过DS.FixtureAdapter
.
楷模:
App.Post = DS.Model.extend
title: DS.attr('string')
comments: DS.hasMany('App.Comment')
App.Comment = DS.Model.extend
text: DS.attr('string')
# I'm not specifying DS.belongsTo('post') because comments could also exist
# with other objects.
# Anyway, it does not work even with it.
适配器:
App.Adapter = DS.FixtureAdapter.extend()
App.Adapter.map App.Post,
comments:
embedded: 'always'
店铺:
App.store = DS.Store.create
revision: 11
adapter: App.Adapter.create()
夹具:
App.Comment.FIXTURES = []
App.Post.FIXTURES = [
{
id: "1"
title: "My post"
comments: [{
id: "1"
text: "My first comment"
}, {
id: "2"
text: "My second comment"
}]
}
]
在控制台中:
post = App.store.find(App.Post, 1);
comments = post.get("comments");
console.log(comments.get('length')); // => 1
firstComment = comments.get('firstObject');
console.log(firstComment.get('id')); // => undefined
console.log(firstComment.get('name')); // => TypeError: Cannot call method `hasOwnProperty` of undefined
使用的 Ember 版本:
- 主数据上的余烬数据
- 余烬v1.0.0-pre.2-311-g668783a
编辑
这是说明问题的 JSFiddle。而且我还在这里写了一个失败的测试。