vendredi 5 décembre 2014

backbone fetching/adding model to collection without an url (but from the models)


Vote count:

0





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() doesn't return anything (instead of the collection's objects).


I guess it's a problem of waiting that the collection has been correctly populated but I thought it was ok be cause I wait for model fetching success before .add it.


when I console.log(toresolvelist) it shows me that the result is here. But I can't access it through .get or toJSON so I guess console.log is cheating me.


I'm having an hard time to identify what's the problem and I could solve it.


Thanks a lot in advance!



asked 1 min ago







backbone fetching/adding model to collection without an url (but from the models)

Aucun commentaire:

Enregistrer un commentaire