从渲染Backbone.View方法触发事件

时间:2014-01-10 08:37:37

标签: javascript backbone.js triggers backbone-views

我有一个带渲染方法的Backbone.View block实例:

render: function() {
        this.$el.html(_.template(this.tpl, this.model.toJSON())).removeClass('load');
        this.trigger('render', this);
        return this;
    }

为此实例添加侦听器,如下所示:

block = new App.View.Block();

button = new App.View.Button();
button.listenTo(button, 'render', button.refresh);

但触发render未触发。

视图block正在从initialize()方法渲染。如果我直接致电block.trigger('render'),listenTo将会工作

1 个答案:

答案 0 :(得分:0)

你的意思是?

渲染块时渲染按钮?

block  = new App.View.Block();
button = new App.View.Button();

// have the button listen to its parent, and render itself (same as refreshing)
button.listenTo( block, 'render', button.render );