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

后端 未结 3 629
慢半拍i
慢半拍i 2021-01-05 02:15

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

相关标签:
3条回答
  • 2021-01-05 02:25
    App.ApplicationView = Ember.View.extend({
      afterRender: function () {
        Ember.run.next(this, function () {
          // This will run one time, after the full initial render.
        });
      }
    });
    
    0 讨论(0)
  • 2021-01-05 02:38

    The didInsertElement is the right place, but if you want to be completely sure your render queue is completely flushed you could also listen to the afterRender event, something like this:

    App.ApplicationView = Ember.View.extend({
      didInsertElement: function() {
        Ember.run.scheduleOnce('afterRender', this, 'processChildElements');
      },
    
      processChildElements: function() {
        // do here what you want with the DOM
      }
    });
    

    Hope it helps.

    0 讨论(0)
  • 2021-01-05 02:41

    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
        }
    });
    
    0 讨论(0)
提交回复
热议问题