var RippleId = Backbone.Model.extend({
initialize: function(toresolve) {
this.url= config.rippleaccount.id.urlModel+toresolve;
this.set('id', toresolve)
}
});
var RippleIds = Backbone.Collection.extend({
model: RippleId,
createIdList: function(toresolves) {
var self = this;
_.each(toresolves, function(toresolve) {
var model = new RippleId(toresolve);
model.fetch({
success: function(model,response) {
self.add(model);
}
});
});
}
});
var toresolvelist = new rippleids();
toresolvelist.createIdList(toresolves);
toresolvelist.toJSON()
不會返回任何內容(而不是集合的對象)。獲取並添加模型到集合
我想這是一個等待收集已正確填充的問題,但我認爲這是好的,因爲我在添加模型之前等待模型獲取成功。
當我console.log(toresolvelist)
它告訴我,結果在這裏。但我無法通過.get
或toJSON
訪問它,所以我猜console.log
正在欺騙我。
我很難確定問題是什麼,我無法解決它。
非常感謝!
http://stackoverflow.com/questions/11459244/backbone-js-empty-array-attribute/11463190 #11463190和http://stackoverflow.com/questions/8413500/backbone-js-populating-a-collection/8415515#8415515或http://stackoverflow.com/questions/26781970/returning-a-backbone-collection-and - 通過不與一個視圖/ 26782761#26782761 – nikoshr 2014-12-05 14:44:41
謝謝深入瞭解 – 2014-12-05 14:50:57
其實我理解這個問題,但仍然無法正確解決它; =/ – 2014-12-05 15:45:02