GUI:setVisible(JM_show, true)
local item_Panel_1 = GUI:getChildByName(JM_show, "item_Panel_1")
local ListView_fj = GUI:getChildByName(JM_show, "ListView_fj")
GUI:removeAllChildren(ListView_fj)
local bagItems = SL:GetMe
🤖 回答引擎: 前端Lua |
🕒 时间: 2026-05-05 02:08:47 |
👁️ 阅读: 18
要在 `itemWidget` 上添加点击事件,你可以使用 `GUI:addOnClickEvent` 函数。这个函数可以为控件绑定一个点击回调。
在你的代码中,创建物品显示控件后,直接添加事件即可。修改后的代码如下:
```lua
-- 创建物品显示控件
local x = SL:GetMetaValue("CURRENT_OPERMODE") == 1 and 15 or 0
local y = SL:GetMetaValue("CURRENT_OPERMODE") == 1 and 15 or 0
local itemWidget = GUI:ItemShow_Create(item_bj, "fj_item" .. posInPage, x, y, itemDataTable)
-- 为物品控件添加点击事件
GUI:addOnClickEvent(itemWidget, function()
SL:print("物品被点击了!物品Index:", itemData.Index)
-- 这里可以添加你需要的其他逻辑,比如打开详情、使用物品等
end)
```
**注意:** `GUI:addOnClickEvent` 是996引擎前端提供的标准事件绑定函数,适用于 `GUI:ItemShow_Create` 创建的物品显示控件。
← 返回问答库