Knockout.js网址路由

Tom*_*Tom 4 sammy.js knockout.js

我做了我的第一个基因敲除应用程序http://jsfiddle.net/Pqs7e/

对于显示应用程序部分(书籍部分,关于部分),我使用jquery $(“#id”)。show()。我觉得这是不正确的方法。如何通过viewmodel的机制做到这一点?

7za*_*rk7 5

实现此目的的另一种方法是使用模板:

<div data-bind="template: state">
    Template renders here
</div>
Run Code Online (Sandbox Code Playgroud)

然后,可以在这样的某个位置(在同一文件或其他位置)定义您的部分:

<script id="books" type="text/html">
   Your markup here...
</script>

<script id="about" type="text/html">
   Your markup here...
</script>
Run Code Online (Sandbox Code Playgroud)