如何在Backbone中添加多个模型到集合
formatChannelIds: function() {
_this = this;
// var activeIds ='';
_.filter(_this.modelChannelList.toJSON(), function(channelObj) {
if (channelObj['isactive'] == true) {
// activeIds =activeIds+','+channelObj['id'];
console.log(channelObj['id']);
_this.modelChannelStats.fetch({
data: {
channel: channelObj['id']
},
processData: true
}, {
success: function(model, response, options) {
_this.channelstatsCollection.push(model);
}
});
}
});
console.log(_this.channelstatsCollection);
console.log(_this.modelChannelStats);
}
我的集合在数组中显示为null。
答案 0 :(得分:-1)
Fetch方法接受一个包含所有必要参数的对象。
_this.modelChannelStats.fetch({
data: {
channel: channelObj['id']
},
processData: true,
success: function(model, response, options) {
_this.channelstatsCollection.push(model);
}
});
尝试使用这段代码。