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

后端 未结 3 654
慢半拍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: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.

提交回复
热议问题