Backbone.Collection.fetch ():
fetch: function(options) { options = options ? _.clone(options) : {}; if (options.parse === void 0) options.parse = true; var success = options.success; options.success = function(collection, resp, options) { var method = options.update ? 'update' : 'reset'; collection[method](resp, options); if (success) success(collection, resp, options); }; return this.sync('read', this, options); },
So, here, your function passed is assigned to var succees .
collection[method](resp, options); The 'reset' method is also called in your case.
collection.reset should go through and add all your models, fire all the events along the way. I don’t know exactly what is going on, but it goes through collection.reset , collection.add , model.add , etc .... I did not follow all this.
I'm not sure what the problem is, I'm sorry about that. Hopefully I will at least help you try something, so maybe we can figure it out. The string if (success) success(collection, resp, options) is a call to your succes function. What you can try to do is make your success callback to the accepted passed arguments and console them:
success: function(collection, resp, options) { console.log(collection); // this might do the trick. // if not, you could try the following collection.on("reset", function(c, options) { console.log(c); // see what that gives ya. }); }
Another thing, I could not find anywhere in the source or documents where collection.fetch uses the add option. If I missed this, please let me know that I would like to consider it.
Good luck let me know what you find. It might be worth going step by step through the debugger.
Hell, it also seems to me that the console often showed me the most current version of collection objects when it shouldn't.
try comforting the length of the collections or something else:
var len = $this.Messages.length; console.log(len); //... // or in the success callback var len = collection.length; console.log(len);