ビューを使用し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
ビューの値は変更されません。なんで?私は何を間違っていますか?