Reputation: 4685
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?
ie.
MyView: Ember.View.extend
#Boaring normal stuff here
didInsertElement: ->
$('.some-class').doSomething()
and
{{view Ember.TextField valueBinding="someField" class="some-class"}}
Does not work because the values of .some-class
are a not set yet.
I don't want to use a setTimeout
and create a race condition.
Upvotes: 1
Views: 1119
Reputation: 12011
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.
As written in the docs:
Ember.run(myContext, function(){
// code to be executed in the next RunLoop, which will be scheduled after the current one
});
Upvotes: 4