In Backbone.js, after I perform a collection.fetch

2019-05-30 10:03发布

问题:

I called fetch, and it hits the server.

Now...my server returns models back...how can I get those just-added models?

回答1:

the fetch method has a success callback with the following signature:

success: function(collection, response){

}

the collection argument is your collection with the newly added models as well as whatever was there previously. response is the json response from the server. So you could look up the models in collection using the ids from response to get the 'just-added models'.