Backbone.js的查看删除和解除绑定 [英] Backbone.js View removing and unbinding

查看:110
本文介绍了Backbone.js的查看删除和解除绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页打开时,我所说的收集和填充视图:

when my page opens, I call the collection and populate the view:

var pagColl = new pgCollection(e.models); 
var pagView = new pgView({collection: pagColl});

另外(通过日期选择器),我希望要填充不同的型号相同的收集和再实例化视图。

Separately (via a Datepicker), I wish to want to populate the same collection with different models and instantiate the view again.

我的问题是,如何关闭原始 pagView ,并清空 pagColl 之前,我打开了新的,因为这鬼观正在为我的问题。上文提到的变量是局部变量?难道是我需要建立一个全球性 pagColl 复位()呢?

The problem I have is how to close the original pagView and empty the pagColl before I open the new one, as this "ghost view" is creating problems for me. The variables referred to above are local variables? is it that I need to create a global pagColl and reset() this?

推荐答案

以及出现了许多讨论这个话题实际上,
骨干并没有什么给你,你必须做你自己,这是你要照顾的是什么:

well there has been many discussion on this topic actually, backbone does nothing for you, you will have to do it yourself and this is what you have to take care of:


  1. 删除视图(这代表将jQuery和jQuery从DOM中删除)

  1. removing the view (this delegates to jQuery, and jquery removes it from the DOM)

// to be called from inside your view... otherwise its  `view.remove();`
this.remove();

这将删除DOM视图,并删除绑定到它所有的DOM事件。

this removes the view from the DOM and removes all DOM events bound to it.

删除所有骨干事件

// to be called from inside the view... otherwise it's  `view.unbind();`
this.unbind();

这将删除绑定到视图中的所有事件,如果在您的视图(按钮)有一定的事件,委托给调用 this.trigger功能('myCustomEvent',则params);

this removes all events bound to the view, if you have a certain event in your view (a button) which delegates to a function that calls this.trigger('myCustomEvent', params);

如果你想要一些想法是如何实现的系统,我建议你在德里克 - 贝利对僵尸观点的博文念起来:<一href=\"http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/\">http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/.

if you want some idea's on how to implement a system I suggest you read up on Derrick Bailey's blogpost on zombie views: http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/.

另一种选择

另一个选择是将重用当前视图,并将它重新渲染或追加在视图中某些项目,势必集合的的 重置 事件

another option would be to reuse your current view, and have it re-render or append certain items in the view, bound to the collection's reset event

这篇关于Backbone.js的查看删除和解除绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆