You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

触发含多参数的Incisor应用事件遇阻,如何让回调获取多参数?

解决Incisor应用事件多参数传递问题

控制台输出:

spinResult Defined

spinResult Callback Added

5

undefined **(我期望此处显示"7777")**

TestAppEvent: CODE VALIDATION FAILED: 'string=' expects the parameter 'string' to be type 'string', but type 'undefined' was provided

解决方案一:将多参数包装为对象传递

修改事件触发逻辑,把多个参数合并到单个对象中传递:

// 触发事件时传递包含所有参数的对象
nc.appEvents.spinResult.trigger({ resultData: 5, message: "7777" });

同时调整回调函数,从对象中提取对应参数:

spinResultCallback(data)
{
    console.log(data.resultData); // 输出5
    console.log(data.message); // 输出"7777"
    
    this.text.string = data.message;
}

解决方案二:定义事件时声明参数列表

在定义事件时,添加参数名称数组,明确告知Incisor事件需要传递的参数项:

// 定义事件时指定参数列表
nc.defineAppEvent("spinResult", ["resultData", "message"]);

这种方式下,你原有的trigger调用和回调函数无需修改,就能正确接收两个参数,控制台会输出期望的5和7777,同时类型错误也会消失。

问题根源

你的代码中第二个参数message为undefined,是因为Incisor默认未声明参数列表时,只会传递第一个触发参数,导致回调无法获取后续参数。通过上述两种方式,要么用对象打包参数,要么提前声明参数列表,就能让回调正确接收所有参数。

内容的提问来源于stack exchange,提问作者Boston_CrazyToothStudio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 13:00:56