Ember.js Ember.View didRender活动
我构建了一个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
并创建竞争条件。
那么,发生了什么,是在插入视图后更新了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 });