admin管理员组文章数量:1356322
I have one single-page application with three sub-pages.
Url structure is:
/page (sub-page-0)
/page#sub-page-1
/page#sub-page-2
View Model is:
function ViewModel(activePage){
var self=this;
self.activePage=ko.observable(activePage);
self.changePage=function (newPage){
self.activePage(newPage);
//change url
});
}
When user enter url I want to get # part in javascript and construct ViewModel with this parameter.
When user click link in the page I want to change URL and load that sub page.
I have one single-page application with three sub-pages.
Url structure is:
/page (sub-page-0)
/page#sub-page-1
/page#sub-page-2
View Model is:
function ViewModel(activePage){
var self=this;
self.activePage=ko.observable(activePage);
self.changePage=function (newPage){
self.activePage(newPage);
//change url
});
}
When user enter url I want to get # part in javascript and construct ViewModel with this parameter.
When user click link in the page I want to change URL and load that sub page.
Share Improve this question asked Aug 9, 2012 at 8:34 Oguz KaradenizliOguz Karadenizli 3,5057 gold badges43 silver badges75 bronze badges2 Answers
Reset to default 5You could use one of the solutions from the stack overflow question: How can I get query string values in JavaScript?
However, I strongly remend you consider a client side routing library. The knockout homepage has an example using sammyjs, but there are many other interesting solutions out there (including knockback, which bines backbonejs and knockoutjs).
Knockout itself does not support navigation. But you can use third party frameworks. There is a tutorial named "Single page applications" from knockout at http://learn.knockoutjs./ which shows how to do that with sammy.js.
本文标签: javascriptFluent navigation with knockoutjsStack Overflow
版权声明:本文标题:javascript - Fluent navigation with knockout.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744001533a2573943.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论