是否有一个后视图更改钩子(很像didInsertElement)? [英] Is there an after view change hook (much like didInsertElement)?

查看:96
本文介绍了是否有一个后视图更改钩子(很像didInsertElement)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 didInsertElement hook,我可以做一些需要的jQuery插件初始化。但是,如果属性更改,Ember将重新呈现该视图,但不再调用 didInsertElement 。大概这是因为元素已经在DOM上,只有某些片段已经改变了。

Using the didInsertElement hook, I'm able to do some jQuery plugin initialization that is needed. However, if a property changes, Ember re-renders the view, but does not call didInsertElement again. Presumably this is because the element is already on the DOM and only certain pieces have changed.

我的问题是,是否有一种我可以覆盖的方法,或其他一些方法通过一个 Ember.View 之后将DOM渲染到DOM中,实际插入到DOM中?

My question is, is there a method I can override, or some other way to access what's been rendered to the DOM by an Ember.View AFTER its actually inserted into the DOM?

我尝试使用 afterRender ,但没有起作用。

I attempted to use afterRender, but it did not work.

推荐答案

我想出了一个很不寻常的方法来解决这个问题。您可以使一个句柄帮助器在视图部分被重新渲染时触发一个事件。我正在使用Bootstrap和jqPlot,需要说明的是,当div可用于绘制图表时。与我的帮手你可以这样做:

I came up with a slightly unusual way of tackling this problem. You can make a handlebars helper that fires an event when the view portion is re-rendered. I was using Bootstrap and jqPlot and needed to be able to tell, say, when the div was available to draw a chart into. With my helper you can do this:

{{#if dataIsLoaded}}
    {{trigger didRenderChartDiv}}
    <div id="chartHost"></div>
{{/if}}

这篇关于是否有一个后视图更改钩子(很像didInsertElement)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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