相关疑难解决方法(0)

在骨干js中重新创建已删除的视图

骨干js中的View.remove()函数从DOM中删除视图本身的容器元素,防止重新创建已删除的视图.知道如何处理这种情况

这是我的代码,

var AttributeView = Backbone.View.extend({
        el: $("#attrs"),
        template:_.template($('#attrs-template').html()),

        initialize:function() {
        },


        render:function (eventName) {
            $(this.el).html(this.template(this.model.toJSON()));
            return this;
            },

        dispose:function(eventName){
            this.unbind();
            this.remove();
        },

    });


var attrView = new AttributeView();
....
attrView.dispose();
//Later on some event I do the below
attrView = new AttributeView()
attrView.render();
Run Code Online (Sandbox Code Playgroud)

上面的最后两行不会重新创建视图,因为id ="attrs"的div不再存在.

javascript backbone.js

8
推荐指数
1
解决办法
4423
查看次数

标签 统计

backbone.js ×1

javascript ×1