backbone.js - Saving model on each change, except the first initial fetch -


i'm sure it's common , basic backbone question, couldn't find answer

i save model after each change, except initial fetch server.

for example:

  mymodel = backbone.model.extend({     url: "mymodelurl",     initialize: function () {       this.on("change", this.save, this);     }   }); 

when fetching it, since has data, change event, , save triggered again

 var mymodel = new mymodel({id:"123"});   mymodel.fetch();  

is there way avoid first save on first fetch? (e.g. if model fetched, don't save)

could way bootsrtap models?

e.g. based on documentation, way it?

note fetch should not used populate collections on page load — models needed @ load time should bootstrapped in place. fetch intended lazily-loading models interfaces not needed immediately: example, documents collections of notes may toggled open , closed.

edit:

one issue see bootstrapping - seems have fetch entire collection on page load, can't fetch small parts of it. why? because if routes use hash tag, on page refresh, server side won't know route i'm in (hash part not sent server). e.g. if use pushstate: true can able bootsrap right model / collection on page refresh, missing something?

sync event fired when model fetched. listen sync once. later listen change event on model.

var self;      this.listentoonce(model,'sync', function(){    self.listento(model,'change',self.changehandler); }); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -