我想收集有关如何在 EmberJS 1.0 中为 hasMany 关系创建记录的规范答案。
似乎有大量过时的文档,我不知道去哪里找。
自 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');
父对象,其中“父对象”是父对象的名称。