Thursday, 15 September 2011

javascript - backbone.js doesn't fire my events -



javascript - backbone.js doesn't fire my events -

i writing backbone.js app, , have problem. collections not fire events, can spot problem in code bellow? render-feedback, initializer feedback.. append method never called. know "../app" returns list tro json items. , can see these beingness created in collection. why event not called?

window.tablesinspectorview = backbone.view.extend({ tagname: "div", initialize: function () { console.log('initializing window.tablesinspectorview'); // setup tables this.data = new backbone.collection(); this.data.url = "../app"; this.data.fetch(); // event binds.. this.data.on("change", this.render , this); this.data.on("add" , this.append_item, this); }, render: function(){ console.log("render"); _.each(this.data.models, this.append_item); }, append_item: function(item) { console.log("appended"); } });

according knowledge , backbone fetch() asynchronous event , when completes reset event triggered ,

when models belonging collection (this.data) modified , change event triggered, im guessing have not got part correct.

so :

window.tablesinspectorview = backbone.view.extend({ tagname: "div", initialize: function () { console.log('initializing window.tablesinspectorview'); // setup tables this.data = new backbone.collection(); this.data.url = "../app"; this.data.fetch(); // event binds.. this.data.on("reset", this.render , this); //change here this.data.on("add" , this.append_item, this); // dont see this.data.add() in code assuming never called ? }, render: function(){ console.log("render"); _.each(this.data.models, this.append_item); }, append_item: function(item) { console.log("appended"); } });

javascript backbone.js

No comments:

Post a Comment