backbone.js - Is it possible to trigger an event when initializing a model? -


in backbone model, possible trigger event in initialize function, nested view? based current code off example: https://stackoverflow.com/a/8523075/2345124 , have updated backbone 1.0.0. here initialize function, model:

var edit = backbone.model.extend({     initialize: function() {         this.trigger('marquee:add');          this.on('change', function(){             this.trigger('marquee:add');         });     }     ... } 

i'm trying call method rendermarquee when model initialized:

var editrow = backbone.view.extend({     initialize: function() {         this.listento(this.model, "change", this.render);   // works         this.listento(this.model, "marquee:add", this.rendermarquee);  // called when changed, not when created     ... } 

rendermarquee is called when model changed, not when initialized. 'change' events work expected (this.render called). thoughts?

thanks!

this doesn't make lot of sense because initializing model somewhere prior doing view.listento call. unfortunately, don't have choice in matter.

you going want move event handling backbone.collection has built in events can listen on adding/removing.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -