Ember.js Ember.View didRender事件 [英] Ember.js Ember.View didRender event

查看:195
本文介绍了Ember.js Ember.View didRender事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个ember.js应用程序,也绑定到一些其他jQuery插件。我有一些形式字段,我需要调用一个jQuery插件,一旦视图被呈现。我尝试挂钩到 didInsertElement ,但显然绑定的表单字段的值不是在插入时分配。当视图完全呈现或绑定初始化时,是否存在回调?

I building a ember.js app that also ties into some other jQuery plugins. I have some form fields that I need to call a jQuery plugin against once the view is rendered. I've tried hooking into didInsertElement, but apparently the values for the bound form fields are not assigned at insertion. Is there a callback in existence for when the view completely renders or when bindings are initialized?

MyView: Ember.View.extend
    #Boaring normal stuff here

    didInsertElement: ->
        $('.some-class').doSomething()

>

and

{{view Ember.TextField valueBinding="someField" class="some-class"}}

无效,因为 .some-class 的值尚未设置。

Does not work because the values of .some-class are a not set yet.

我不想使用 setTimeout 并创建比赛条件。

I don't want to use a setTimeout and create a race condition.

推荐答案

好了,发生了什么,是在插入视图后更新testValue绑定。所以你可以做的是调用 $('。silly-field')。doSomethingSilly(); 里面 Ember.run.next

Well, what is going on, is that the testValue binding is updated after the view is inserted. So what you can do is to call $('.silly-field').doSomethingSilly(); inside an Ember.run.next() function.

如文档中所写:

Ember.run(myContext, function(){
 // code to be executed in the next RunLoop, which will be scheduled after the current one
});

这篇关于Ember.js Ember.View didRender事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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