Ember.js Ember.View didRender事件(Ember.js Ember.Vie

2019-10-17 01:53发布

我建立一个ember.js的应用程序,也关系到一些其他的jQuery插件。 我有我需要调用一个jQuery插件,针对一旦视图渲染某种形式的领域。 我试图钩住didInsertElement ,但显然对于绑定表单字段的值在插入未分配。 有没有存在一个回调时的观点完全呈现或绑定时初始化?

即。

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

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

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

不起作用,因为的值.some-class是一个没有被设定。

我不希望使用setTimeout和创造竞争条件。

Answer 1:

那么,到底是怎么回事,是该视图插入后的测试值绑定更新。 所以,你可以做的是调用$('.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
});


文章来源: Ember.js Ember.View didRender event