模块:测试调用数据
可在模块:测试调用数据/doc创建此模块的帮助文档
local p = {}
local db = require('模块:测试数据库')
local dataList = db.char_skill_data
p["编号查询"] = function(frame)
-- 查询角色编号
local owner_num = frame.args['角色编号']
if not owner_num then
return "缺少角色编号参数"
end
mw.log("收到参数: " .. owner_num)
-- 提取数据
local filteredData = {}
for _i, v in ipairs(dataList) do
if v.owner_order == owner_num then
for _, skill in ipairs(v.owner_skill) do
table.insert(filteredData, skill)
end
mw.log("成功查询到角色编号: " .. owner_num)
end
end
if #filteredData > 0 then
-- 按 skill_order 排序
table.sort(filteredData, function(a, b)
return tonumber(a.skill_order) < tonumber(b.skill_order)
end)
mw.log("完成排序")
-- 创建 HTML
local html = mw.html.create('ul')
for _i, v in ipairs(filteredData) do
if v.skill_name_cn then
html:tag('li'):wikitext(v.skill_name_cn)
end
end
return tostring(html)
else
mw.log("未找到匹配的技能数据")
return "未找到匹配的技能数据"
end
end
return p