phteven
phteven

Reputation: 1383

In EmberJS, what is the function called to execute jQuery plugin after the templates are done rendering?

I've tried "didInsertElement" but that didn't seem to work, the markup doesn't exist and then the jQuery plugin code executes too fast.

Upvotes: 2

Views: 936

Answers (2)

zaius
zaius

Reputation: 6409

Make sure you're using the inbuilt jQuery selector on the view - this.$() - that will work even if the element hasn't been inserted yet.

didInsertElement: function() {
  this.$().jQueryPlugin();
}

Upvotes: 3

Roy Daniels
Roy Daniels

Reputation: 6309

Would you provide a jsFiddle of your issue? Also, try doing:

didInsertElement: function() {
  Ember.run.next(optionalContext, function() {
    // Your code here
  });
}

That will run your code at the end of the current runloop which should guarantee that all rendering and bindings have executed.

But please provide a jsFiddle so a more precise answer can be given.

Upvotes: 4

Related Questions