最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to update view manually in Ember.js? - Stack Overflow

programmeradmin5浏览0评论

I am using Ember.js in my application, but there is a point where I update a property of the view's context(controller) but right after the update there is a parser(MathJax) that looks at the dom for the updated fields to parse it into math. However even though the update is taking place, it happens after mathjax looks for the update. What I need to do is force ember to update the view or wait for ember to update before I tell mathjax to parse the html. Is there a way to achieve this?

I am using Ember.js in my application, but there is a point where I update a property of the view's context(controller) but right after the update there is a parser(MathJax) that looks at the dom for the updated fields to parse it into math. However even though the update is taking place, it happens after mathjax looks for the update. What I need to do is force ember to update the view or wait for ember to update before I tell mathjax to parse the html. Is there a way to achieve this?

Share Improve this question asked Jan 6, 2013 at 22:31 justkashjustkash 7092 gold badges13 silver badges30 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 17

This is a fairly mon use-case. 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. For example:

App.MathView = Ember.View.extend({
  controller: null,
  template: Ember.Handlebars.pile("<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')
});

See the Ember Managing-Asynchrony Guide and API docs for Ember.run: http://emberjs./guides/understanding-ember/managing-asynchrony/ http://emberjs./api/classes/Ember.run.html#method_next

发布评论

评论列表(0)

  1. 暂无评论