In my app, the user creates a collection with a bunch of models. As I don't want to make a ton of requests to the server, I've created a custom function that saves these models in batch to the server. The server then responds with all the models including their id, and this is then set to the various models. All working well so far.
The problem I'm having now is that Backbone doesn't know that at this point all models are synced with the server. So at a later point in the app, when I call model.save() on each model, it sends each model to the server again (which should be only the ones that are changed since the batch operation). How could I let Backbone know that all models are synced? I was looking at the 'changed' and 'hasChanged' attributes, but am not quite sure if I should manipulate these (I guess not).
Backbone does not include the feature of tracking changed attributes since last sync with server.
The changed and hasChanged are not dealing with changed attributes since last sync with server.
You will have to create your own mechanism for tracking the state of your models:
hasChangedSinceLastSync flag.change event and set the flag to true.sync method and set the flag to false once data is returned from the server (for read/create/update).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With