Backbone 的 View 销毁

更新日期: 2015-12-12 阅读次数: 8649 分类: BackboneJS

我的思路

当监听到 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();

可能造成的隐患?

参考

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式