我正在使用 ASP.NET MVC、Knockout、nav.js 等构建单页应用程序,
两个视图模型:
- 父视图模型;
- 子视图模型;
FatherViewModel 拥有所有 Navigation 方法,FatherViewModel 拥有 SonViewModel 的实例,
问:如何从 SonViewModel 访问那些 Navigation 方法?
FatherViewModel = function () {
var self = this;
var dataSource = {...}
self.sonViewModel = new SonViewModel();
self.nav = new NavHistory({
params: {...},
onNavigate: function (navEntry) {...}
}).initialize({ linkToUrl: true });
//navigation methods:
self.gotoHomePage = function (){...}
}
SonViewModel = function () {
var self = this;
var dataSource = {...}
//...
}