假设我在微光中有一个简单的组件,其中包含项目列表
<todo-list @items={{ items }}></todo-list>
模板.hbs
<ul>
{{#each @items key="@index" as |item|}}
<li onclick={{ action clickme }}>{{ item }}</li>
{{/each}}
</ul>
组件.ts
import Component, { tracked } from '@glimmer/component';
export default class TodoList extends Component {
constructor(options) {
super(options);
}
clickme() {
// how do I access the parent context from here?
}
}
即使我从父母那里传递了一个动作
<todo-list @items={{ items }} @rootclickme={{ rootclickme }}></todo-list>
更新,template.hbs
<ul>
{{#each @items key="@index" as |item|}}
<li onclick={{ action @rootclickme }}>{{ item }}</li>
{{/each}}
</ul>
在我的外部 component.ts
rootclickme () {
// I don't have access to parent variables here either?
// only what's within the scope of the function itself?
}
我想要做的是有一个带有列表的组件。单击列表项时,我希望它在顶部弹出一个单击事件,以便父组件可以决定隐藏列表并显示此选定项的更详细视图。
我该如何在微光中做到这一点?在反应我会通过
注意:我没有使用完整的 ember.js,只是 glimmer.js 独立