Monday, 15 February 2010

ember.js - How to change parent view classname on child view load? -



ember.js - How to change parent view classname on child view load? -

i need alter parent view classname on kid view load code

var childview = em.view.extend({ willinsertelement : function() { this.get('parentview').set('classnames',['childview']); }, template : em.handlebars.compile(template) });

regards chandru.

use classnamebindings , send event kid view update property.

consider example:

{{#view app.aparentview}} {{view app.achildview}} {{/view}}

the app:

app = ember.application.create(); app.aparentview = em.view.extend({ bgcolor: 'lightgray', classnames: ['parent-view'], classnamebindings: 'bgcolor', updatebg: function(bg) { this.set('bgcolor', bg); } }); app.achildview = em.view.extend({ classnames: ['child-view', 'blue'], willinsertelement: function() { this.get('parentview').send('updatebg', 'green'); } });

the css see working:

html, body { margin: 20px; } .parent-view { padding: 4rem; } .child-view { padding: 2rem; } .lightgray { background-color: lightgray; color: black; } .blue { background-color: blue; } .green { background-color: green; }

see jsbin here.

ember.js

No comments:

Post a Comment