能否从模板向小部件操作注入参数?

实际上,我的问题无法通过上述方式解决:

  • 是的,通知级别确实被修改了,但是…
  • 它并没有被保存。需要点击其他地方通过其他操作来保存。

通过在 GitHub 代码数据库中大量搜索随机关键词,我找到了一些类似这样的结构:
{{d-button action=(action "up" wc) ...}}

经过一些测试,我得出了以下结论:

  • 模板:
    {{d-button action=(action "操作名称" arg1 arg2) ...}}`
    
  • JS:
    api.modifyClass("component:some-component", {
        actions: {
            操作名称(arg1, arg2, argA, argB) {
                console.log(arg1);
                console.log(arg2);
                console.log(argA);
                console.log(argB);
            }
        }
    })
    

方法的第一个参数 arg1arg2 是由模板提供的。其余参数 argAargB 等可能由组件的特性决定(例如,category-notifications-button 会根据用户点击的设置返回一个整数)。

我完全不确定我所写的内容是否正确,但这或许能帮助那些和我提出同样问题的人。