我正在使用durandaljs
并加载一个shell
视图,然后加载一个内部视图:page1
. 我正在绑定 中的某些项目shell
,我希望可以从内部视图中更改这些项目:即page1
. 例子:
shell.html
<div class="container">
<div data-bind="text: someValue"></div>
<section id="content" class="main container-fluid">
<!--ko compose: {model: router.activeItem,
afterCompose: router.afterCompose,
transition: 'entrance'} -->
<!--/ko-->
</section>
</div>
shell.js
define(['durandal/plugins/router', 'global'],
function (router, global) {
function activate() {
global.shellViewModel = shell;
return router.activate('page1');
}
var shell = {
//...
someValue: ko.observable('hello world'),
activate: activate
};
return shell;
});
page1.js
define(['durandal/plugins/router', 'global', 'viewmodels/shell'],
function (router, global, shell) {
function activate() {
return;
}
var page1SomeValue = ko.computed(function() {
shell.someValue('hello world');
});
var vm = {
//...
activate: activate,
somePage1Value: somePage1Value
};
return vm;
});
page1
加载时会global.shellViewModel.someValue('hello world');
执行,但shell
视图上的值不会改变。为什么?我究竟做错了什么?