Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Knockout.js url routing

I did my first knockout.js application http://jsfiddle.net/Pqs7e/

For display application parts (books section, about section) I use jquery $("#id").show(). I feel this is not right way. How can I do this through the mechanism of the viewmodel?

like image 979
Tom Avatar asked Jan 17 '23 12:01

Tom


1 Answers

An alternate way to do this is with templates:

<div data-bind="template: state">
    Template renders here
</div>

Then your sections can be defined somewhere like this (in the same file or elsewhere):

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

<script id="about" type="text/html">
   Your markup here...
</script>
like image 183
7zark7 Avatar answered Jan 25 '23 07:01

7zark7