ember.js - 如何在 ember js 中一次只打开一个菜单项?
问题描述
我们在 ember js 中有一个页面,它有多个菜单。单击图标时,菜单应打开,单击关闭按钮时,菜单应关闭。唯一的问题是,当您单击一个然后再单击第二个时,它们都同时打开,但我们想要的是一次只打开一个。对于如何解决这个问题,有任何的建议吗?
{{#if showMenu}}
<div> Menu items </div>
{{/if}}
showMenu(){
this.set('showMenu', true);
},
hideMenu(){
this.set('showMenu', false);
},
解决方案
恕我直言,使用eq
来自ember-truth-helpers
然后基本上这个js:
@tracked openMenu = null;
showMenu(name){
this.openMenu = name;
},
hideMenu(){
this.openMenu = null;
},
这个hbs:
<button {{on "click" (fn this.showMenu 'menuOne')}}>show one</button>
{{#if (eq this.openMenu "menuOne")}}
show menu 1
{{/if}}
<button {{on "click" (fn this.showMenu 'menuTwo')}}>show two</button>
{{#if (eq this.openMenu "menuTwo")}}
show menu 1
{{/if}}
<button {{on "click" this.hideMenu}}>close all</button>
推荐阅读
- angular - 更改 firebase-messaging-sw.js 位置
- python - 如何将我的 django 路径设置为 http://127.0.0.1:8000/myproject/admin
- erlang - mnesia:read 在 mnesia 中使用表碎片时返回空,但有记录
- scala - 在播放控制器中注入模拟服务对象的依赖项,同时对其进行单元测试
- artifactory - JFrog Artifactory 中的本地仓库、远程仓库和虚拟仓库有什么区别
- javascript - 如何在 Javascript 中将“ArrayBuffer”转换为“SharedArrayBuffer”?
- python - 如何复制具有特定扩展名的文件夹目录中的文件并将其保存到新文件夹而不覆盖复制的文件?
- activejdbc - Is there a way to detach model object instances from the database?
- python - Python将矩阵插入另一个矩阵
- javascript - 使用函数在返回或抛出之间进行选择