I have some jQuery code which needs to be run when a view is rendered. For the initial render I can easily do
App.FooView = Ember.View.extend({
didInsertElement: function() {
console.log("the view was rendered");
this.$().someStuff();
}
});
but since the someStuff()
method is manipulating properties of the view elements, I need to run it when the view is re-rendered due to data bindings, because it will lose the custom generated properties.
If you would like to re-render the view when a certain attribute changes then what you want would look something like this:
App.FooView = Ember.View.extend({
myProperty: 'This value might change',
myPropertyChanged: function() {
//Do some stuff here (maybe change the template) and call...
this.rerender();
}.observes('myProperty')
});
But if you are looking to only re-render the view after the view is created then you want something more like this:
App.FooView = Ember.View.extend({
init: function() {
this._super();
//Do some stuff here (maybe change the template) and call...
this.rerender();
}
});
SOURCE: http://emberjs.com/api/classes/Ember.View.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With