[英]How do I architect single page application using Knockout?
I have begun to play with Knockout recently and I must say it is truly awesome and the power that it can bring to web applications. 我最近开始玩Knockout,我必须说它真的很棒,它可以为Web应用程序带来的力量。
However now I want to do something real world and architect my solution using Knockout. 但是现在我想做一些现实世界并使用Knockout构建我的解决方案。 Eg.
例如。 How should my viewmodels be initialized.
我应该如何初始化我的视图模型。 Where should they go?
他们应该去哪儿? I am mainly targeting single page application.
我主要针对单页面应用程序。 So, I am interested in architecting single page applications mainly.
所以,我主要对构建单页面应用程序感兴趣。
There are a lot of pieces to the puzzle, but here is a short list for me. 拼图有很多部分,但这里有一个简短的清单。
DISCLAIMER: I'll make some assumptions about your app too, so some of it will vary. 免责声明:我也会对您的应用做出一些假设,因此其中一些会有所不同。 Also, this is just one way to do it.
此外,这只是一种方法。 There are may good ways.
可能有很好的方法。 But this should be a good starting point for you.
但这应该是一个很好的起点。
Assuming your app is a set of abut 5 main views in a SPA: 假设您的应用程序是一组SPA中的5个主视图:
I use the Revealing Module Pattern for creation of my viewmodels, though standard Module is perfectly fine too. 我使用Revealing Module Pattern来创建我的视图模型,尽管标准模块也非常好。
If you ave a more specific question, happy to answer that. 如果你有一个更具体的问题,很高兴回答这个问题。 I tried to keep this short cuz in truth it's not a 5 minute answer.
我试着保持这个简短的事实,这不是一个5分钟的答案。 In fact, I'm writing a course for Pluralsight on one way to do this coming in August 2012 :-)
事实上,我正在为Pluralsight写一篇关于2012年8月这样做的方法:-)
I just open-sourced the mini SPA framework I put together with Knockout being the major component. 我只是开源了我将Knockout作为主要组件放在一起的迷你SPA框架。
knockout-spa A mini (but full-fledged) SPA framework built on top of Knockout, Require, Director, Sugar. knockout-spa一个迷你(但功能齐全的)SPA框架,建立在Knockout,Require,Director,Sugar之上。 https://github.com/onlyurei/knockout-spa
https://github.com/onlyurei/knockout-spa
Live Demo: http://knockout-spa.mybluemix.net 现场演示: http : //knockout-spa.mybluemix.net
For those who need an updated alternative (2015)... Another option (and a very good one) is to use Yeoman to scaffold a single-page-app for you as described in Steven Sanderson's blog here 对于那些谁需要更新的备选方案(2015年)......另一种选择(和一个很好的一个)是使用约曼在史蒂芬·桑德森的博客中描述脚手架单页面应用为你在这里
It does all the architecturing you need for you so you can concentrate on writing code. 它完成了您需要的所有架构,因此您可以专注于编写代码。 Try best to harness the re-usability of the knew knockout component feature - it's amazingly described by Steve Sanderson so I won't take away the glory of his well done work.
尽量利用已知淘汰组件功能的可重用性 - 史蒂夫桑德森精心描述这一点,所以我不会带走他干得好的作品的荣耀。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.