逐步增强 - Node.js的,Backbone.js的 [英] Progressive enhancement - Node.js, Backbone.js
问题描述
Node.js的服务器有两个角色:
The node.js server has two roles:
- 在与preFIX / API REST风格的路线API
- 渲染对其他路线的网页(/ /计划/功能/术语...)
有关的那一刻,我所有的网页渲染正在加载网页...与骨干应用Backbone.router启动时,它取代了DOM相结合。
For the moment, all my pages render a "Loading page..." combined with the Backbone application that replaces the DOM when the Backbone.router starts.
我想建立当用户到达一个页面的网站页面服务器端,让骨干处理导航的下一部分,当用户浏览网站。
I would like to build the website pages server-side when an user reaches a page and let Backbone handles the next part of the navigation when the user navigates on the website.
我知道如何当一个页面加载与DOM已经建成,Backbone.router负荷做服务器端,但客户端然后替换DOM,因为它不知道这个观点已经preloaded。
I know how to do it server-side but client-side when a page is loaded with the DOM already built, the Backbone.router loads and then replaces the DOM because it does not know that the view is already preloaded.
如何解决它的客户端?
code:
主页视图: http://pastebin.com/qS1tHUfq
查看条款: http://pastebin.com/et1mrbLK
更新:新的code: https://gist.github.com/mathieug/d50c861e63dd647f1c2b 结果
现在我需要在第一负荷被称为runSlider方法。
Update: the new code: https://gist.github.com/mathieug/d50c861e63dd647f1c2b
Now I need the runSlider method to be called at the first load.
推荐答案
在启动历史,一定要通过 {沉默:真正}
作为一个选项,让主干知道你已经加载一个完整的页面。这将prevent从更换DOM当视图已经是路由器preloaded(第一次)。
When you start the History, make sure to pass {silent: true}
as an option to let Backbone know that you've already loaded a complete page. This will prevent the router from replacing the DOM when the view is already preloaded (the first time).
如果服务器已经呈现的整个页面,并启动历史,传,当你不希望初始路径触发沉默:真正的
If the server has already rendered the entire page, and you don't want the initial route to trigger when starting History, pass
silent: true
.
所以,你的code应该是这样的:
So, your code should look like:
Backbone.history.start({pushState的:真正的,无声的:真正});
这篇关于逐步增强 - Node.js的,Backbone.js的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!