Backbone.js event after view.render() is finished

前端 未结 7 1448
天命终不由人
天命终不由人 2020-11-29 05:48

Does anyone know which event is fired after a view is rendered in backbone.js?

7条回答
  •  感情败类
    2020-11-29 06:22

    Or you can do the following, which is what Backbone code is supposed to look like (Observer pattern, aka pub/sub). This is the way to go:

    var myView = Backbone.View.extend({ 
        initialize: function() {  
            this.on('render', this.afterRender);
    
            this.render();
        },
    
        render: function () {  
            this.trigger('render');
        },
    
        afterRender: function () {
        }
    });
    

    Edit: this.on('render', 'afterRender'); will not work - because Backbone.Events.on accepts only functions. The .on('event', 'methodName'); magic is made possible by Backbone.View.delegateEvents and as such is only available with DOM events.

提交回复
热议问题