我有一个model
:
window.LayerModel = Backbone.Model.extend({
defaults:{
'id':'unknow',
'type':'unkonw',
'preId':'unknow',
'data': {}
}
}
然后我定义了一个集合:
window.LayerManageCollection = Backbone.Collection.extend({
model: LayerModel
})
然后我在视图中初始化它:
window.LayerMasterManageView = Backbone.View.extend({
initialize: function () {
//here I have a gobal javascript variable named "localdata"
//which have 17 items in an array,each of them is object type
this.collection = new LayerManageCollection(localdata);
console.log('this collection', this.collection);
}
}
但是集合的长度是1!,只有一个模型!,
奇怪的是,如果更改"defaults"
为"default"
,收集结果是我想要的,长度为 17
为什么会这样?我怎么解决这个问题?