繼承MODEL2屬性我有一個模型,收集骨幹從MODEL1屬性
Model1 = Backbone.Model.extend();
Model2 = Backbone.Model.extend({
defaults: {
code:'',
m1_id: ?????, // this part should get the Model1 "id" attribute
id: '' // e.g. the value of m1.get('id');
}
});
C = Backbone.Collection.extend({
model: Model2
});
,使每個
var m1 = new Model1();
var m2 = new Model2();
var c = new C();
一個實例,並設置值
m1.set({'code':'0001', 'type': 'O', id: 1});
c.add({'code':'sample1', 'id':1}); // note: i did not set the m1_id
c.add({'code':'sample2', 'id':2});
但模型裏面收集得到Model1 id attrtibute,類似
集合必須具有此
c.at(0).toJSON();
-> {'code':'sample1', 'm1_id': 1, id: 1} // note: the "m1_id" value is
c.at(1).toJSON(); // from Model1 "id" attribute
-> {'code':'sample2', 'm1_id': 1, id: 2}
我怎麼能自動從型號1屬性設置Model2的屬性集合裏面..謝謝!
遺憾的錯字錯誤.. =)反正,什麼IM試圖弄清楚我們的..如果有一種方法,如果我的插圖新模式,以收集不設置m1_id/parent_id它會自動設置..謝謝! – jrsalunga