user1156041
user1156041

Reputation: 2195

add updated model into Backbone Collections

I used collection create method to save the model into the server. But this create method automatically adds the stale model into the collection.

I am trying to do the following things.

Do I need to extend the collection create method? Or is there another way?

Upvotes: 0

Views: 28

Answers (1)

T J
T J

Reputation: 43156

From the docs:

Creating a model will cause an immediate "add" event to be triggered on the collection, a "request" event as the new model is sent to the server, as well as a "sync" event, once the server has responded with the successful creation of the model. Pass {wait: true} if you'd like to wait for the server before adding the new model to the collection.

(emphasis mine)

That'll look like:

collection.create({ // attributes
},{wait: true});

Upvotes: 1

Related Questions