我真的陷入了由Ember数据引起的大量问题,并且缺乏嵌入式记录支持.
我搜索了整个网络,大多数帖子已经过时,其他的已经过时+要求我使用第三方库或连接300行特殊代码有很多缺点.
我不知道如何使用嵌入式记录和今天的ember-data?
编辑:现在有一个新的文档http://emberjs.com/api/data/classes/DS.EmbeddedRecordsMixin.html
我无法embedded hasMany使用ember数据正常工作.
我有类似的东西
App.Post = DS.Model.extend({
comments: DS.hasMany('App.Comment')
});
App.Comment = DS.Model.extend({
post: DS.hasMany('App.Post'),
name: attr('string')
});
Run Code Online (Sandbox Code Playgroud)
我的API返回以下内容GET /post:
[
{
id: 1
comments: [{name: 'test'}, {name: 'test2'}]
},
...
]
Run Code Online (Sandbox Code Playgroud)
我需要发送以下内容POST /post:
[
{
comments: [{name: 'test'}, {name: 'test2'}]
},
...
]
Run Code Online (Sandbox Code Playgroud)
我想与Ember模型合作并让他们提出适当的要求:
var post = App.store.createRecord(App.Post, hash_post_without_comments);
post.get('comments').createRecord(hash_comment);
App.store.commit(); // This should call the POST api
Run Code Online (Sandbox Code Playgroud)
和
var posts = App.store.find(App.Post); // This should call the GET api
Run Code Online (Sandbox Code Playgroud)
当我尝试类似的东西时post: DS.hasMany('App.Post', {embedded: …