我在 main.js 中定义了根路由器,并在其中拥有导航代码。在页面上有一个列表,我想从选定的列表项中打开查看页面。我可以通过在 html 页面中使用 $root.router.retreive() 来获取页面上的数据。
如何在其相应的 viewModel 中获得该值?
导航代码:
self.gotoPage = function(data, event)
{
self.router.store(data.id);
self.router.go(event.target.id);
};
绑定代码:
oj.Router.sync().then(
function () {
// bind your ViewModel for the content of the whole page body.
ko.applyBindings(new RootViewModel(), document.getElementById('globalBody'));
},
function (error) {
oj.Logger.error('Error in root start: ' + error.message);
}
);