Destroy or remove a view in Backbone.js

后端 未结 7 1648
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 09:57

I\'m currently trying to implement a destroy/remove method for views but I can\'t get a generic solution to work for all my views.

I was hoping there would be an eve

相关标签:
7条回答
  • 2020-11-27 10:59

    I had to be absolutely sure the view was not just removed from DOM but also completely unbound from events.

    destroy_view: function() {
    
        // COMPLETELY UNBIND THE VIEW
        this.undelegateEvents();
    
        this.$el.removeData().unbind(); 
    
        // Remove view from DOM
        this.remove();  
        Backbone.View.prototype.remove.call(this);
    
    }
    

    Seemed like overkill to me, but other approaches did not completely do the trick.

    0 讨论(0)
提交回复
热议问题