使用Backbone删除视图

时间:2012-08-30 09:17:37

标签: backbone.js

我有一个像这样的视图:

(function(views) {
    views.FilterView = Backbone.View.extend({
        tagName: 'div',
        events: {
            'click a.remove': 'remove'
        },
        template: _.template($("#filterViewTemplate").html()),

        render: function() {
            this.$el.html(this.template());
            return this;
        },
        remove: function (e) {
            this.remove();
            this.unbind();
        }
    });
})(app.views);

它的模板是:

<script type="text/html" id="filterViewTemplate">
    <select class="filterByOption">
        <option value="Account">Account</option>
        <option value="Owner">Owner</option>
    </select>

    <span class="cell sort">
        <input class="filterString cell" type="text" />
    </span>
    <a href="#" class="btn small remove">Remove</a>
</script>

但是当我点击Remove时,我收到以下错误:

Uncaught RangeError: Maximum call stack size exceeded

1 个答案:

答案 0 :(得分:3)

这是因为在您的remove方法中,您拨打this.remove()的来电remove()拨打remove()来拨打remove() ...

相关问题