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