假设我们有组件answer,它具有isOpen属性。默认情况下,isOpen是false,当用户单击answer时,我们将isOpen更改为true。我们正在展示答案列表。当用户点击第二个answer时,如何关闭第一个m1n 7o1p?我在考虑用globalIsOpen = false创建一个服务answersSync。
answer
isOpen
false
true
globalIsOpen = false
answersSync
watbbzwu1#
我建议跟踪父组件中哪个答案是开放的,即列出答案的组件。然后,您的父模板将如下所示:
{{#each this.answers as |answer|}} <Answer @answer={{answer}} isOpen={{eq this.currentlyOpenAnswer answer}} {{on "click" (fn this.openAnswer answer)}} /> {{/each}}
(然后在父组件的js中添加代码,跟踪currentlyOpenAnswer,响应openAnswer操作)
currentlyOpenAnswer
openAnswer
1条答案
按热度按时间watbbzwu1#
我建议跟踪父组件中哪个答案是开放的,即列出答案的组件。然后,您的父模板将如下所示:
(然后在父组件的js中添加代码,跟踪
currentlyOpenAnswer
,响应openAnswer
操作)