javascript - How to override Backbone.sync? -


i'm trying out backbone.js, , 1 of things i'm trying make call remote api, need able override backbone.sync, understand the documentation.

there isn't example of how in documentation itself, , there doesn't appear google group backbone... can point out example doing this?

take @ annotated source example overwrite backbone.sync localstorage alternative

backbone-localstorage

basically backbone.sync should function takes 4 arguments:

backbone.sync = function(method, model, options) { }; 

you need fire either options.success or options.error depending on whether method succeeded. methods in format:

  • "create" : expected create model on server
  • "read" : expected read model server , return it
  • "update" : expected update model on server argument
  • "delete" : expected delete model server.

you need implement 4 methods , define whatever want "server"

of course these things backbone.sync must implement. may implement more methods , may pass more paramaters success it's best not this.

it's best make sure same backbone.sync programming interface rather implementation. if want switch out modified backbone.sync localstorage 1 won't have extend match extended backbone.sync"

[edit]

also note can use multiple implementations of sync. every reference backbone.sync actaully (this.sync || backbone.sync) have like:

var mymodel = backbone.model.extend({      ...      "sync": myownspecificsync,      ... }); 

backbone.sync default global 1 models use unless models have sync method set.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -