继续讨论来自 Discourse 主题开发者指南:
大家好,
我在想是否可以从模板向操作注入参数,但在 @Johani 的指南中未能找到肯定或否定的答案。我的目标是让模板生成多个组件,而每个组件的操作能够知晓 {{#each}} 循环中的参数。
例如,在选择分类通知多选按钮后:
<script type="text/x-handlebars" data-template-name="components/some_component">
{{#each categories as |c|}}
{{category-notifications-button
value=c.notification_level
category=c
onChange=(action "changeCategoryNotificationLevel" ***以某种方式注入 c 作为参数***)
}}
{{/each}}
</script>
<script type="text/discourse-plugin" version="0.8">
api.modifyClass("controller:some_component", {
actions: {
changeCategoryNotificationLevel(selected_value, ***c 作为参数***) {
c_as_a_parameter.setNotification(notificationLevel);
}
}
}
});
</script>
在 changeCategoryNotificationLevel 内部,是否有办法知道当前来自模板的是哪个分类?
如果不能,如果我的问题描述得足够清楚,是否有人能看到其他实现相同效果的方法?
提前感谢