Nikita Hismatov
Nikita Hismatov

Reputation: 1656

Backbone dummy: understanding collection synchronization

I want to synchronise my collection each time an item is added.

So if user adds an item in another browser window - the server still sends us valid data.

And so... I got stuck! I read the docs a couple of times, but still can't undersand:

Upvotes: 0

Views: 298

Answers (1)

CD..
CD..

Reputation: 74176

  • which method sends the data to server?

model.save([attributes], [options]) :

Save a model to your database (or alternative persistence layer), by delegating to Backbone.sync.

  • which method parses items from server's response and puts them into the collection?

model.parse(response) or collection.parse(response):

parse is called whenever a model's data is returned by the server, in fetch, and save. The function is passed the raw response object, and should return the attributes hash to be set on the model. The default implementation is a no-op, simply passing through the JSON response. Override this if you need to work with a preexisting API, or better namespace your responses.

Upvotes: 1

Related Questions