EmberJS 1.0 HasMany关系创建记录

时间:2013-10-02 16:35:53

标签: ember.js

我想收集关于如何在EmberJS 1.0中为hasMany关系创建记录的规范答案。

看到大量过时的文档,我不知道在哪里看。

1 个答案:

答案 0 :(得分:2)

自ED 1.0 beta 2以来,以下一直在为我工作:

var child = this.get('store').createRecord('child', {
   name: 'New Child',
   parent: parent
};
child.save();

parent.get('children').addObject(child);
// My backend automatically adds the inverse of relationships when saving     
// the child, so I don't need to save the parent separately

其中parent是父对象。您可能需要在控制器中指定needs: ['parent'],然后使用var parent = this.get('controllers.parent.content');获取父级,其中“parent”是父对象的名称。

相关问题