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

前端 未结 7 1429
天命终不由人
天命终不由人 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:37

    I realise this question is fairly old but I wanted a solution that allowed the same custom function to be called after every call to render, so came up with the following...

    First, override the default Backbone render function:

    var render = Backbone.View.prototype.render;
    Backbone.View.prototype.render = function() {
        this.customRender();
        afterPageRender();
        render();
    };
    

    The above code calls customRender on the view, then a generic custom function (afterPageRender), then the original Backbone render function.

    Then in my views, I replaced all instances of render functions with customRender:

    initialize: function() {
        this.listenTo(this.model, 'sync', this.render);
        this.model.fetch();
    },
    
    customRender: function() {
        // ... do what you usually do in render()
    }
    
    0 讨论(0)
提交回复
热议问题