我想知道是否可以检索同一数组中表的属性。例如这里我想检索我的数组的“list.index”属性,该怎么做?
{
category_title = "Weapon",
description = nil,
type = "list",
list = {items = {"Give", "Remove"}, index = 1},
style = {},
action = {
onSelected = function()
if list.index == 1 then
-- it's 1
else
-- it's 2
end
end
},
最佳答案
创建表时不可能在另一个条目中使用一个条目。
但是由于您正在定义一个函数,因此您可以这样做:
onSelected = function(self)
if self.list.index == 1 then
-- it's 1
else
-- it's 2
end
end
只需确保以表格作为参数调用 onSelected 即可。
关于lua - 从 LUA 中的同一个表中检索属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71519610/