0

I have a knockoutjs single page application with a help page template which inside it contains anchors tags/sections with names like "general", "purchases" etc. I am using knockout js templating

Help.html
<p><a href="#general">General</a></p>
<p><a href="#purchases">My Purchases</a></p>

<a name="general"></a>
General info
<a name="purchase"></a>
Purchases help

I have some other html with links

<a href="#" data-bind="click: $root.navViewModel.clicked.bind($data, 'help#general')">Learn    More</a>
<a href="#" data-bind="click: $root.navViewModel.clicked.bind($data, 'help#purchases')">Learn    More about Purchases</a>

In navViewModel.clicked I am taking data and setting the templateName to the value. In this case it would be 'help#general' or 'help#purchases'. This doesn't work as it looks for a template names help#general.html

I also tried a click binding to extract template name (help) and the fragment (general or purchases) and set template name to name and do a afterRender to add fragment to window.location.hash. This doesn't seem to work either.

Could you please let me know if you have done this and how you implemented it to got a section/fragment within a page on click using KnockoutJS?

Thanks.

4

0 回答 0