Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Ember.js, how do I run some JS after a view is rendered?

Tags:

ember.js

How do I run a function after an Ember View is inserted into the DOM?

Here's my use-case: I'd like to use jQuery UI sortable to allow sorting.

like image 536
Marc Hughes Avatar asked Jan 16 '12 13:01

Marc Hughes


People also ask

How does Ember js work?

Ember uses templates to organize the layout of HTML in an application. Ember templates use the syntax of Handlebars templates. Anything that is valid Handlebars syntax is valid Ember syntax. Here, {{name}} is a property provided by the template's context.

Is Ember js a frontend?

Ember. js is an opinionated frontend JavaScript framework that has been getting a lot of interest lately.

How good is Ember js?

Ember. js offers you a well-organized and trustworthy framework. When the development team is big, this is the framework that suits best. It allows everyone to understand the written code and contribute to a common project.


1 Answers

You need to override didInsertElement as it's "Called when the element of the view has been inserted into the DOM. Override this function to do any set up that requires an element in the document body."

Inside the didInsertElement callback, you can use this.$() to get a jQuery object for the view's element.

Reference: https://github.com/emberjs/ember.js/blob/master/packages/ember-views/lib/views/view.js

like image 115
Roy Daniels Avatar answered Oct 05 '22 23:10

Roy Daniels