Appearance
二维表变量数据管理接口 Table
具体函数名及描述如下:
序号 | 函数名 | 函数描述 |
---|---|---|
1 | Clear(...) | 清理表格数据 |
2 | InsertValue(...) | 在末尾插入一行数据 |
3 | InsertValueByRow(...) | 在某行插入一行数据 |
4 | GetValue(...) | 获取表格数据 |
5 | GetAllValue(...) | 获取表格数据 |
6 | SetValue(...) | 设置表格数据 |
7 | RemoveRow(...) | 删除序列号的值 |
8 | GetValuesByCol(...) | 获取某列的所有值 |
9 | GetRows(...) | 获取行数 |
10 | GetCols(...) | 获取列数 |
11 | GetColIndex(...) | 获取列索引 |
12 | GetRowIndex(...) | 获取指定列和值的行索引(默认判断值相等) |
13 | GetRowIndexs(...) | 获取指定列和值的所有行索引(默认判断值相等) |
14 | GetTableColKeys(...) |
Clear
lua
local isSuccess = Data.Table:Clear(varId)
if isSuccess then
print("清除表格成功")
end
local isSuccessPlayer = Data.Table:Clear(playerVarId, Player:GetHostUin())
if isSuccessPlayer then
print("清除玩家表格成功")
end
InsertValue
- 参数及类型:
- 返回值及类型:
- value:any返回的值
- 该方法的主要作用: 在末尾插入一行数据
- 具体使用案例如下:
lua
local isSuccess = Data.Table:InsertValue(varId, nil, 2, "aa", false)
if isSuccess then
print("插入表格值成功")
end
local isSuccessPlayer = Data.Table:InsertValue(playerVarId, Player:GetHostUin(), 2, "aaa", false)
if isSuccessPlayer then
print("插入玩家表格值成功")
end
InsertValueByRow
- 参数及类型:
- 返回值及类型:
- value:any返回的值
- 该方法的主要作用: 在某行插入一行数据
- 具体使用案例如下:
lua
local isSuccess = Data.Table:InsertValueByRow(varId, nil, {2, "sss3", false}, 1) -- 在第一行插入一行数据
if isSuccess then
print("按行插入表格值成功")
end
local isSuccessPlayer = Data.Table:InsertValueByRow(playerVarId, Player:GetHostUin(), {2, "sssa", false})-- 在最后一行插入一行数据
if isSuccessPlayer then
print("按行插入玩家表格值成功")
end
GetValue
- 参数及类型:
- 返回值及类型:
- value:any返回的值
- 该方法的主要作用: 获取表格数据
- 具体使用案例如下:
lua
local value = Data.Table:GetValue(varId, nil, 2, 2)
if value then
print("获取表格值", value)
end
local playerValue = Data.Table:GetValue(playerVarId, Player:GetHostUin(), 2, 1)
if playerValue then
print("获取玩家表格值", playerValue)
end
GetAllValue
lua
-- 获取后的数据格式是
-- {
-- {10, "RRR", 0},-- 第一行
-- {9, "sss", 0}, -- 第二行
-- {0, "fff", 0}, -- 第三行
-- }
local allValues = Data.Table:GetAllValue(varId)
if allValues then
print("获取表格所有值", allValues)
end
local playerAllValues = Data.Table:GetAllValue(playerVarId, Player:GetHostUin())
if playerAllValues then
print("获取玩家表格所有值", playerAllValues)
end
SetValue
- 参数及类型:
- 返回值及类型:
- ret:
bool
成功(true)
- ret:
- 该方法的主要作用: 设置表格数据
- 具体使用案例如下:
lua
local ret = Data.Table:SetValue(varId, playerId, row, col, value)
RemoveRow
- 参数及类型:
- 返回值及类型:
- ret:
bool
成功(true)
- ret:
- 该方法的主要作用: 删除序列号的值
- 具体使用案例如下:
lua
local isSuccess = Data.Table:RemoveRow(varId, nil, 1) -- 移除第一行
if isSuccess then
print("移除表格行成功")
end
local isSuccessPlayer = Data.Table:RemoveRow(playerVarId, Player:GetHostUin(), {2, 4}) -- 移除第二行和第四行
if isSuccessPlayer then
print("移除玩家表格行成功")
end
GetValuesByCol
- 参数及类型:
- 返回值及类型:
- ret:
bool
成功(true)
- ret:
- 该方法的主要作用: 获取某列的所有值
- 具体使用案例如下:
lua
local values = Data.Table:GetValuesByCol(varId, nil, 1)
if values then
print("获取表格列值", values)
end
local playerValues = Data.Table:GetValuesByCol(playerVarId, Player:GetHostUin(), 2)
if playerValues then
print("获取玩家表格列值", playerValues)
end
GetRows
lua
local rows = Data.Table:GetRows(varId)
if rows then
print("获取表格行数",rows)
end
local size = Data.Table:GetRows(playerVarId, Player:GetHostUin())
if size then
print("获取玩家表格行数",size)
end
GetCols
lua
local cols = Data.Table:GetCols(varId)
if cols then
print("获取表格列数",cols)
end
local num = Data.Table:GetCols(playerVarId, Player:GetHostUin())
if num then
print("获取玩家表格列数",num)
end
GetColIndex
lua
local colIndex = Data.Table:GetColIndex(varId, nil, "名称")
if colIndex then
print("获取表格列索引", colIndex)
end
local playerColIndex = Data.Table:GetColIndex(playerVarId, Player:GetHostUin(), "分数")
if playerColIndex then
print("获取玩家表格列索引", playerColIndex)
end
GetRowIndex
- 参数及类型:
- 返回值及类型:
- size:
number
行数
- size:
- 该方法的主要作用: 获取指定列和值的行索引(默认判断值相等)
- 具体使用案例如下:
lua
local rowIndex = Data.Table:GetRowIndex(varId, nil, 2, "sss")
if rowIndex then
print("获取表格行索引", rowIndex)
end
local playerRowIndex = Data.Table:GetRowIndex(playerVarId, Player:GetHostUin(), 3, true)
if playerRowIndex then
print("获取玩家表格行索引", playerRowIndex)
end
GetRowIndexs
- 参数及类型:
- 返回值及类型:
- size:
number
行数
- size:
- 该方法的主要作用: 获取指定列和值的所有行索引(默认判断值相等)
- 具体使用案例如下:
lua
local rowIndexs = Data.Table:GetRowIndexs(varId, nil, 2, "sss")
if rowIndexs then
for key, value in pairs(rowIndexs) do
print("获取表格行索引", value )
end
end
local playerRowIndexs = Data.Table:GetRowIndexs(playerVarId, Player:GetHostUin(), 3, false)
if playerRowIndexs then
for key, value in pairs(playerRowIndexs) do
print("获取玩家表格行索引", value )
end
end
GetTableColKeys
参数及类型:
返回值及类型:
该方法的主要作用:
具体使用案例如下:
lua
local colKeys = Data.Table:GetTableColKeys(varId)