在现有 itemRenderer 里给三个子节点绑定同一个回调即可。截图里的 chk 是新 UI 的 GButton,不是 Laya.CheckBox:
const bind = (node: Laya.GWidget, type: "chk" | "img" | "txt") => {
node.off(Laya.Event.CLICK, this, this.onPartClick);
node.on(Laya.Event.CLICK, this, this.onPartClick, [index, type, node]);
};
bind(chk as Laya.GButton, "chk");
bind(img, "img");
bind(label, "txt");
private onPartClick(index: number, type: string, node: Laya.GWidget, evt: Laya.Event): void {
evt.stopPropagation();
const value = type === "img" ? (node as Laya.GImage).src
: type === "chk" ? (node as Laya.GButton).selected
: (node as Laya.GTextField).text;
console.log(type, index, this.temparray[index], value);
}
stopPropagation() 会阻止同时触发列表项的 ClickItem;如果两种监听都需要,把这行删掉。
以上由 AI(codex)自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。