Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute code once after all views have completely rendered in Ember.js

Tags:

ember.js

Something like document ready, but after all Ember views rendering

I am doing this right now with an override on ApplicationView didInsertElement, which seems to be working so far:

App.ApplicationView = Em.View.extend({
  didInsertElement: function() {
    // Do your magic.
  }
});

I am wondering if this is the right way for an Ember document ready, or if Ember has a more native support for this simple and very common thing.

like image 317
clueless Avatar asked Aug 04 '13 22:08

clueless


1 Answers

You can easily add a "post render" hook by reopening the base View class and adding it into the render queue.

Here's some code to show you how:

Ember.View.reopen({
    didInsertElement : function() {
        this._super();
        Ember.run.scheduleOnce('afterRender', this, this.didRenderElement);
    },
    didRenderElement : function() {
        // Override this in your View's
    }
});
like image 136
Elliot Anderson Avatar answered Dec 06 '22 13:12

Elliot Anderson