backbone.js - Update values passed to Backbone view -


in addone m creating new object of view that

this.section = "aaa"; var sectionview = new aa(model:this.model,section:this.section); 

section global variable of view m passing aa view.but after passing section value change @ end of add 1 this

this.section = "aaa"; var sectionview = new aa(model:this.model,section:this.section); . . . . . . this.section = "sss"; 

then how can update value of section passed @ time of creation of view aa??? expected answer is

this.options.section = "sss" not "aaa" 

in aa view

the usual approach sort of thing extend backbone.events build global pub/sub event dispatcher:

window.pub_sub = _({}).extend(backbone.events); 

then view listen events pub_sub:

initialize: function() {     this.listento(pub_sub, 'change:section', this.section_changed);     //... }, section_changed: function(section) {     this.section = section;     // , whatever else needs happen... } 

then trigger event when change section:

pub_sub.trigger('change:section', new_section_value); 

you'd want funnel changes global section through single function call somewhere ensure events triggered should doing sort of thing anyway.

demo: http://jsfiddle.net/ambiguous/rptfs/

if need these settings persist change pub_sub global settings model , use usual model persistence mechanisms.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -