How can I bind to a view re-render in Ember.js?

后端 未结 2 952
慢半拍i
慢半拍i 2021-02-09 19:15

I have some jQuery code which needs to be run when a view is rendered. For the initial render I can easily do

App.FooView = Ember.View.extend({
  didInsertElemen         


        
2条回答
  •  别那么骄傲
    2021-02-09 20:11

    In addition to Akash's explanation, you would want to use the didInsertElement hook instead of the init hook to only re-render after the view is created. So it would look more like:

    App.FooView = Ember.View.extend({
        didInsertElement: function() {
            this.rerender();
        }
    });
    

    Although, I'm not exactly sure why you'd need to rerender after the view has already rendered.

提交回复
热议问题