开关骨干意见的页面之间进行导航 - 什么正确的方法是什么? [英] Switching views in backbone for navigating between pages - whats the right way?

查看:104
本文介绍了开关骨干意见的页面之间进行导航 - 什么正确的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做出了决定,我的应用程序的路由切换到客户端,而不是服务器端。这意味着我需要一种方式,用户浏览该网站切换视图和退出页面。我能找到一个试图记录这种情况的唯一的事情就是这篇文章:如何切换使用Backbone.js的意见

我看到这是如何工作的,但我不认为是这样做的一个很好的方式。我想保留我的意见 - 因为这是整点吧?要为您的应用程序的部分区分不同的视图?我认为有一个大的内容查看,然后就拉东西到它,并重新渲染是有点粗糙,绕过所有酷模块化你可以做,否则。

那么,什么是去它的最佳方式?理想的情况是我想类似的是,在上述文章记录了功能,但需要一个骨干视图作为参数。<​​/ P>

解决方案

我已经写了关于这个问题的几篇文章:

<一个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/

和一个较新的,从这个职位需要的想法,并正式确定更:

<一个href=\"http://lostechies.com/derickbailey/2011/12/12/composite-js-apps-regions-and-region-managers/\">http://lostechies.com/derickbailey/2011/12/12/composite-js-apps-regions-and-region-managers/

重新使用视图实际上是在大多数情况下,一个反模式。通常有很多额外的code和参与持有查看实例额外的克鲁夫特,让他们把自己重新连接到DOM和正确处理注册DOM事件。此外,运行内存泄漏使用了太多的内存的风险(我的第一篇文章谈论它),并摧毁你的应用程序的性能。

如果您的看法使用的是昂贵的资源,你应该缓存的资源你的意见外,并重新使用它。您的意见应该是廉价和快速的创建,渲染,展示和销毁。

I have made a decision to change my application routing to client side rather than server side. This means I will need a way to switch views in and out of the page as the user navigates the site. The only thing I could find that attempts to document this is this article: How to switch views using Backbone.js

I see how this would work, but I don't think is a great way of doing it. I want to keep my views - as that's the whole point right? To have separate views for the distinguishable parts of your application? I think having one big "ContentView" and then just pulling stuff into it and re-rendering is a bit crude and bypasses all the cool modularisation you can do otherwise.

So what is the best way to go about it? Ideally I want a function similar to what is documented in the aforementioned article, but takes a backbone view as its argument.

解决方案

I've written a few articles on this subject:

http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/

and an newer one that takes the idea from this post and formalizes it more:

http://lostechies.com/derickbailey/2011/12/12/composite-js-apps-regions-and-region-managers/

re-using views is actually an anti-pattern in most cases. there's usually a lot of additional code and extra cruft involved in holding on to view instances, to get them to re-attach themselves to the DOM and handle registered DOM events correctly. Additionally, you run the risk of memory leaks (which my first article talks about) and destroying your application performance by using up too much memory.

If your views are using an "expensive" resource, you should cache that resource outside of your views and re-use it. Your views should be cheap and fast to create, render, display, and destroy.

这篇关于开关骨干意见的页面之间进行导航 - 什么正确的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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