What technique shall one use to implement batch insert/update for Backbone.sync?
标签:
backbone.js
相关问题
- Backbone.js PushState routes .htaccess only workin
- Updating a LayoutView's Model
- Disable Backbone.js hashes entirely, but keep push
- Is there an easy way to distribute a Flask server
- React + Backbone, Target container is not a DOM el
相关文章
- Get all models in backbone collection where attrib
- How can I dynamically set a className for a Backbo
- Nesting Views within Views in backbone js
- Backbone-relational hasmany best practices
- JavaScript error: “is not a constructor”
- Marionette + i18n in templates
- Rendering reCAPTCHA v2.0 widget within Backbone vi
- Backbone.js PUT/DELETE problems with Codeigniter R
Here's how I did it
works fine for me , and I use it to control every ajax request coming out of any model or collection
I guess it depends on your usage scenarios, and how much you want to change the calling code. I think you have two options:
Option 1: No Change to client (calling) code
Oddly enough the annotated source for Backbone.sync gives 'batching' as a possible reason for overriding the
sync
method:Instead of actually saving on sync, add the request to a queue, and only batch-save every so often.
_.throttle
or_.delay
might help you here.Option 2: Change client code
Alternatively, instead of calling
save
on your models, you could add some sort ofsave
method to collections. You'd have to track which models were actually modified and hence in need of update, since as far as I can tell, Backbone only knows whether they're new or not (but I could be wrong about that).