1

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

IE。

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

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

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

不起作用,因为 的值.some-class尚未设置。

我不想使用 asetTimeout并创建一个竞争条件。

4

1 回答 1

4

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

正如文档中所写:

Ember.run(myContext, function(){
 // code to be executed in the next RunLoop, which will be scheduled after the current one
});
于 2012-07-30T20:06:22.180 回答