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

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

问题描述

类似于文档准备就绪,但毕竟 Ember 视图渲染

Something like document ready, but after all Ember views rendering

我现在正在使用对 ApplicationView didInsertElement 的覆盖来执行此操作,到目前为止它似乎正在运行:

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

我想知道这是否是准备好 Ember 文档的正确方法,或者 Ember 是否对这个简单且非常常见的事情有更原生的支持.

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.

推荐答案

通过重新打开基础 View 类并将其添加到渲染队列中,您可以轻松添加后渲染"挂钩.

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天全站免登陆