Destroy or remove a view in Backbone.js

后端 未结 7 1661
没有蜡笔的小新
没有蜡笔的小新 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:45

    I know I am late to the party, but hopefully this will be useful for someone else. If you are using backbone v0.9.9+, you could use, listenTo and stopListening

    initialize: function () {
        this.listenTo(this.model, 'change', this.render);
        this.listenTo(this.model, 'destroy', this.remove);
    }
    

    stopListening is called automatically by remove. You can read more here and here

提交回复
热议问题