Backbone 的 View 销毁

发布时间: 2015-12-12 20:45:34 作者: 大象笔记

我的思路

当监听到 model 被销毁时,触发 view 的 remove 操作。 因为当 model 不存在时,对应的 view 也就没有了存在的意义。 但是怎么判断 model 不存在了呢?

简单粗暴的方式

When using $(el).empty() it removes all the child elements in the selected element AND removes ALL the events (and data) that are bound to any (child) elements inside of the selected element (el).

直接 empty 掉 element。在 View 初始化的时候,调用 $(this.el).empty();

可能造成的隐患?

参考

我是一名山东烟台的开发者,联系作者