I have such code:
var MyModel = Backbone.Model.extend();
var MyCollection = Backbone.Collection.extend({
url: '/url/',
model: MyModel
});
var coll = new MyCollection();
The url is correct and returns correct json. But if I try to use the next code:
$('#fetch').click(function(){
coll.fetch();
console.log(coll.toJSON());
});
- it shows me data only after the second click (http-response in firebug i see after the first one). It seems that data isn't refreshed in time.
If I put each statement in different event it works correct. But I need to know the length of collection immediately. How to do this?
See Question&Answers more detail:os