感叹这对我来说已成为"日常问题"的例行公事,对不起!
我有一个nav.html,其中包含:
<div class="loader pull-right" data-bind="css: { active: router.isNavigating }">
<i class="icon-spinner icon-2x icon-spin"></i>
</div>
Run Code Online (Sandbox Code Playgroud)
麻烦的是,它永远不会停用!旋转器总是保持旋转.
我已经在视图模型中调试了调试,就像在Durandal html示例页面中一样:
var vm = {
activate: activate,
//refresh: refresh,
//sessions: sessions,
title: 'My App Home Page',
activate: function () {
system.log('Lifecycle : activate : home');
},
binding: function () {
system.log('Lifecycle : binding : home');
return { cacheViews: false }; //cancels view caching for this module, allowing the triggering of the detached callback
},
bindingComplete: function () {
system.log('Lifecycle : bindingComplete : home');
},
attached: function (view, parent) {
system.log('Lifecycle : attached : home');
},
compositionComplete: function (view) {
system.log('Lifecycle : compositionComplete : home');
},
detached: function (view) {
system.log('Lifecycle : detached : home');
}
//viewAttached: viewAttached
};
Run Code Online (Sandbox Code Playgroud)
在我的Chrome开发者控制台中,我有:
Lifecycle : bindingComplete : home system.js:73
Lifecycle : attached : home system.js:73
Lifecycle : compositionComplete : home system.js:73
Run Code Online (Sandbox Code Playgroud)
......我会认为"compositionComplete"会触发"router.isNavigating"的结束,不是吗?
nav.html由我的shell.html文件组成,如下所示:
<header>
<!-- ko compose: {view: 'nav'} -->
<!-- /ko-->
</header>
Run Code Online (Sandbox Code Playgroud)
基本上旋转器只是停留在右上方,永远不会消失.我可以在我的两个页面之间导航,它只是停留在那里,即使每次都会激活"compositionComplete".
整个shell.html文件:
<div>
<header>
<!-- ko compose: {view: 'nav'} -->
<!-- /ko-->
</header>
<div>
<section id="content" class="main">
<!--ko router: { transition:'entrance', cacheViews:true }--><!--/ko-->
</section>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
编辑的shell.html文件:
<div>
<header>
<nav class="navbar navbar-default">
<div class="navbar-header">
<a class="navbar-brand" href="/">
<span class="title">My test SPA</span>
</a>
</div>
<div>
<ul class="nav navbar-nav" data-bind="foreach: router.navigationModel">
<li data-bind="css: { active: isActive }">
<a data-bind="attr: { href: hash }, html: title"></a>
</li>
</ul>
<p class="navbar-text pull-right">Logged in as <a href="#" class="navbar-link">Bilbo Baggins</a></p>
<div class="loader pull-right" data-bind="css: { active: router.isNavigating }">
<i class="icon-spinner icon-2x icon-spin"></i>
</div>
</div>
</nav>
</header>
<div>
<section id="content" class="main">
<!--ko router: { transition:'entrance', cacheViews:true }--><!--/ko-->
</section>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这可能是因为你的方式做的组成router中shell.html.
在durandal 2.0中它应该如下所示:
<!--ko router: { transition:'entrance', cacheViews:true }--><!--/ko-->
Run Code Online (Sandbox Code Playgroud)
或者,如果你想保持旧的方式:
<!--ko compose: {model: router.activeItem,
attached: router.attached,
compositionComplete: router.compositionComplete,
transition: 'entrance'} -->
<!--/ko-->
Run Code Online (Sandbox Code Playgroud)
还要考虑到css类active可能无法div在加载gif中按预期工作.相反,你可以使用:
<div class="loader pull-right" data-bind="visible: router.isNavigating">
Run Code Online (Sandbox Code Playgroud)
因此,当未导航时,您将隐藏加载程序gif.