javascript - In Ember how do I update a view after the ArrayController content is modified? -


i'm starting ember forgive me if question seems daft. have arraycontroller holds list of people attribute name. i'm using following handlebars call create textfields each name in content array:

{{#each app.controller}} {{view em.textfield placeholder="name" valuebinding="name" }} {{/each}} 

this working expected. first initialize content array several names , textfield appears each entry. when use pushobject add person content array new textfield not added! using console can see people being added content, view not changing. stranger still, if add people in following manner works expected:

this.pushobject(newperson); var copy = this.get('content'); this.set('content',[]); this.set('content',copy);  

when add people way textfield newly added person. ember documentation says pushobject() kvo-compliant, doesn't mean should update dependencies , view should update? need call rerender() or other function make pushobject() update view or have copy array each time want update view? thanks!

so figured out issue. in init function controller adding elements content array this

app.controller = em.arraycontroller.create({ content: [],  init: function(){     this.insertnew(); },   insertnew: function(){     var t = app.person.create({         name:"test"     });     this.pushobject(t); },     }); 

this code did not change view when insertnew called (though initialization worked). adding this.set("content",[]) init function insertnew behaved expected. here's working code:

app.controller = em.arraycontroller.create({ content: [],  init: function(){     this.set("content",[]);     this.insertnew(); },   insertnew: function(){     var t = app.person.create({         name:"test"     });     this.pushobject(t); },     }); 

i had thought first content:[] line meant did not need set content again later, seems when initializing array have set again.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -