如何绑定到在Ember.js中重新呈现的视图? [英] How can I bind to a view re-render in Ember.js?

查看:85
本文介绍了如何绑定到在Ember.js中重新呈现的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些jQuery代码需要在渲染视图时运行。对于初始渲染,我可以轻松地执行

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();
  }
});

但由于 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

这篇关于如何绑定到在Ember.js中重新呈现的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆