以下代码有什么问题?
var Item = Backbone.Model.extend({
defaults: {
}
});
var List = Backbone.Collection.extend({
model: Item
});
var collection = new List({'variable':this}); //collection is NOT null!
var result = new Item({'collection':collection}); //result.collection is undefined! why?
答案 0 :(得分:3)
将您的项目添加到列表
var collection=new List,
result=new Item({ name: 'my item'});
collection.add( result );
或
collection.create({ name: 'my item'});