Want to update view manually in Ember.js? To specify code that should execute after a property’s changes have propogated, use an observer. Ember triggers observers after it successfully propagates the change.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | App.MathView = Ember.View.extend({ controller: null, template: Ember.Handlebars.compile("<div>{{myProperty}}</div>"), myPropertyDidChange: function() { // From here the controller value is changed but DOM has not been updated Ember.run.next(this, function() { // This code will run when after changes have propagated to the DOM // Call MathJax parser here // If needed you can access the view's DOM element via this.$() alert("New property value is in dom: "+ this.$().text()); }); }.observes('controller.myProperty') }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.