Ember.js 嵌套模型[ember-1.0.0-rc.1+;ember.data-11]
问题1 在ember-1.0.0-rc.1+ember.data-11中创建嵌套模型的概念有什么错误 问题2 使用var line=App.line.find()时,我应该得到行。如何将Andon或Shift作为对象嵌套在一行中?还是只有Andon的颜色 这是我的 非常感谢 关于问题2: 我认为您需要为每个belongsTo添加一个外键,即Shift中的line_id和andon_id以及andon中的Shift_id,然后您需要创建一些序列化程序,在其中可以嵌入/侧载关联。不幸的是,我只熟悉rails中的activeModel序列化程序,它可能无法用于您的案例,但答案中的示例可能会对您有所帮助Ember.js 嵌套模型[ember-1.0.0-rc.1+;ember.data-11],ember.js,ember-data,Ember.js,Ember Data,问题1 在ember-1.0.0-rc.1+ember.data-11中创建嵌套模型的概念有什么错误 问题2 使用var line=App.line.find()时,我应该得到行。如何将Andon或Shift作为对象嵌套在一行中?还是只有Andon的颜色 这是我的 非常感谢 关于问题2: 我认为您需要为每个belongsTo添加一个外键,即Shift中的line_id和andon_id以及andon中的Shift_id,然后您需要创建一些序列化程序,在其中可以嵌入/侧载关联。不幸的是,我只熟悉r
App.Line = DS.Model.extend({
name: DS.attr('string'),
shifts: DS.hasMany('App.Shift'),
});
App.Shift = DS.Model.extend({
name: DS.attr('string'),
// shift 1 <-> 1 shifts
line: DS.belongsTo('App.Line'),
// one-to-one relationship between Shift and Andon
andon: DS.belongsTo('App.Andon')
});
App.Andon = DS.Model.extend({
// one-to-one relationship between Shift and Andon
shift: DS.belongsTo('App.Shift')
})
App.LinesController = Ember.ArrayController.extend({
content: [],
});
App.linesController = Ember.ArrayController.create({
content: [],
init: function(){
var self = this;
self.pushObject(
App.Line.createRecord(
{
...
shifts: [
App.Shift.createRecord(
{
andon: App.Andon.createRecord({...})
}),
App.Shift.createRecord(
{
andon: App.Andon.createRecord({...})
}),
]
},
],
}
),
);
},
});