在Ember.js中完全呈现所有视图后,执行代码一次 [英] Execute code once after all views have completely rendered in Ember.js

查看:83
本文介绍了在Ember.js中完全呈现所有视图后,执行代码一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我现在正在这样做,现在使用ApplicationView didInsertElement进行覆盖,这似乎在工作到目前为止:

  App.ApplicationView = Em.View.extend({
didInsertElement:function(){
/ /你的魔法
}
});

我想知道如果这是Ember文档准备好的正确方法,或者如果Ember有更多本机支持这个简单而非常常见的事情。

解决方案

您可以通过重新打开基本View类并将其添加到渲染队列中轻松添加post render / p>

以下是一些代码,以显示如何:

  Ember.View。重新打开({
didInsertElement:function(){
this._super();
Ember.run.scheduleOnce('afterRender',this,this.didRenderElement);
}
didRenderElement:function(){
//覆盖此视图的
}
});


Something like document ready, but after all Ember views rendering

I am doing this right now with an override on ApplicationView didInsertElement, which seems to be working so far:

App.ApplicationView = Em.View.extend({
  didInsertElement: function() {
    // Do your magic.
  }
});

I am wondering if this is the right way for an Ember document ready, or if Ember has a more native support for this simple and very common thing.

解决方案

You can easily add a "post render" hook by reopening the base View class and adding it into the render queue.

Here's some code to show you how:

Ember.View.reopen({
    didInsertElement : function() {
        this._super();
        Ember.run.scheduleOnce('afterRender', this, this.didRenderElement);
    },
    didRenderElement : function() {
        // Override this in your View's
    }
});

这篇关于在Ember.js中完全呈现所有视图后,执行代码一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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