【发布时间】:2018-02-01 21:22:31
【问题描述】:
我有一个 Aurelia 项目,在 app.html 和 app.js 中有导航。该项目包含一个具有不同样式的主页,包括与非主页视图不同的导航。
我想关闭主页视图的导航,因此我尝试设置一个变量 (showMenu) 来切换可见性。事实上,我可以使用 jQuery 来做到这一点,但我想知道是否有 Aurelia 的方式来做到这一点。如果我将 this.showMenu 设置为 true,它会显示菜单容器,而 false 会隐藏它。比如这样:
app.html
<div class="container" if.bind="showMenu">
app.js
constructor(router){
this.router = router;
this.showMenu = true;
...other things
}
我想做的是从 home.js 将 showMenu 设置为 false。我试过这个(在 20 次左右的其他尝试中),但它不起作用。
home.js
activate() {
this.showMenu = false;
}
有没有办法通过 $parent 或其他方式使用视图模型在 app.html 中隐藏菜单?
编辑
这可行,但感觉有点像 hack。
home.js
import {inject} from 'aurelia-framework';
import {Router} from 'aurelia-router';
@inject(Router)
export class Home {
constructor(router) {
this.router = router;
}
attached(){
$("#navbarMenu").hide();
this.router.refreshNavigation();
}
}
【问题讨论】:
标签: aurelia