简体   繁体   English

一页上有多页

[英]Multiple pages on a single page

I am using backbone.js and building a single page application, inspired by trello.com .. 我正在使用trbone.js,并从trello.com启发构建一个单页应用程序。

I want to know how you show many pages on top of the original page. 我想知道您如何在原始页面顶部显示许多页面。 As in how you architect it. 就像您如何设计它。

How do you use Backbone routers to achieve this? 您如何使用骨干路由器来实现这一目标?

For example in trello 例如在trello

Basepage BasePage的 BasePage的

And then now on top of the base page you have dynamic content 然后,在基础页面的顶部,您便拥有了动态内容

like a cards detail 就像卡片的细节 卡片详细

like a boards details 像木板的细节 板细节

How could i architecture something like this? 我该如何构建这样的东西?

I've done a couple of approaches so far in projects with 50+ pages and they both scaled well. 到目前为止,在50页以上的项目中,我已经完成了几种方法,并且它们都可以很好地扩展。 I did not use backbone.js but the approaches are straight forward and do not require a framework to learn other than I used jQuery for selectors. 我没有使用骨干.js,但是方法很简单,除了我将jQuery用于选择器之外,不需要学习其他框架。

Both of them have in common creating a single overlay window that you can pull in content into the window. 两者都共同创建了一个叠加窗口,您可以将内容拉入窗口。 I wrote mine from scratch but you could easily use jQuery UI dialog. 我是从头开始编写的,但是您可以轻松使用jQuery UI对话框。 The two approaches only differ in how the content is pulled. 两种方法的区别仅在于内容的提取方式不同。 Also, using the information on the link is all you should need to pull in the "module" or overlay content as your rule. 同样,只需使用链接上的信息,即可提取“模块”或叠加内容作为您的规则。 Do not need tons of scripts loaded in to start your app. 无需加载大量脚本即可启动您的应用。 Have the modules pull in the behavior for you. 让模块为您拉动行为。

Option 1) Use the jQuery load method to pull content from stand-alone web pages by using a placeholder variable like so: 选项1)使用jQuery load方法,通过使用占位符变量从独立网页中提取内容,如下所示:

var $ph = $('<div />'); 
$ph.load(URL); // loads gui of remote URL + executes any script that URL has

The $ph var now contains all the GUI loaded in from the external URL so you can use selector on it to extract the particular HTML and place it into your DOM or overlay as you need. $ ph var现在包含从外部URL加载的所有GUI,因此您可以在其上使用选择器来提取特定的HTML,然后根据需要将其放入DOM或覆盖。

Here is an example of the stand-alone HTML output: 这是独立HTML输出的示例:

<div class="module">
    <a class="link">click me</a>
</div>
<script>
(function(){
    // put any private vars here
    $('.module .link').click(function(){
        // do something
    });
})();
</script>

If you remove() or destroy the dom inside the overlay through jQuery, it will automatically remove all the events directly assigned aka "bind" and "unbind" them but using "live" or "delegate" you will need to worry about "die" and "undelegate" etc. just doing die('.namespace').live('click.namespace') will ensure is cleaned. 如果您通过jQuery删除()或销毁覆盖内的dom,它将自动删除所有直接分配为“绑定”和“取消绑定”事件的事件,但使用“实时”或“委托”则需要担心“死亡” ”和“取消删除”等。只需执行die('。namespace')。live('click.namespace')即可确保已清除。

Here is an example of this on one of my websites -> http://www.kitgui.com/docs But the better example is within the customer section as the docs is fairly simple using hash history. 这是我的一个网站-> http://www.kitgui.com/docs上的一个示例,但更好的示例位于“客户”部分,因为使用哈希历史记录的文档相当简单。

2) Using an iframe inside your overlay and assigning it a URL. 2)在叠加层内部使用iframe并为其分配URL。

This is the easiest option but is a little slower because each page called has to have a full standalone behavior and dependencies with the iframe. 这是最简单的选项,但速度稍慢,因为调用的每个页面都必须具有完整的独立行为以及与iframe的依赖关系。 Also you must worry about sizing the frame etc. unless you have a fixed overlay window. 另外,除非您有固定的覆盖窗口,否则您还必须担心框架的大小等。

You must have a loader overlay your iframe while its loading then have the iframe talk the parent to tell it its done loading and hide the loader. 在加载iframe的过程中,您必须让加载程序覆盖您的iframe,然后让iframe与父级联系以告知其已完成加载并隐藏该加载程序。

I did this for several sites but one of them is a site in development you can see here to get the code -> 我在几个站点上都做了这个,但是其中一个是正在开发中的站点,您可以在这里看到获取代码->

http://dev.zipstory.com (sign in and go to my zipstory and click "group" settings etc to see this, just view source to see how I did this as its all there) http://dev.zipstory.com (登录并转到我的zipstory,然后单击“组”设置等以查看此内容,只需查看源代码即可了解我是如何做到这一点的)

The thing about iframes is you should write some code on the parent that accepts standard messages from the iframe that you agree on as a typical set of behavior such as notifying its done loading or passing messages to update something on the parent etc. This can be added on the fly and refactored as you need as long as your aim is KISS approach. 关于iframe的事情是,您应该在父级上编写一些代码,以接受您同意的iframe的标准消息,作为一组典型的行为,例如通知其已完成加载或传递消息以更新父级上的某些内容等。只要您的目标是KISS方法,就可以随时添加和重构。

Each of the 'dynamic content' pages should be a template (underscore.js gives you _.template()) rendered by a backbone view. 每个“动态内容”页面都应该是由主干视图呈现的模板(underscore.js为您提供_.template())。 The main page needs to have events that initialize new views and render the templates. 主页需要具有初始化新视图和呈现模板的事件。 Look at the todos app ( http://documentcloud.github.com/backbone/docs/todos.html ) to get a basic idea about the flow of a backbone app. 查看todos应用程序( http://documentcloud.github.com/backbone/docs/todos.html ),以获得有关骨干应用程序流程的基本思想。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM