模块:View

可在模块:View/doc创建此模块的帮助文档

local p = {} --p stands for package

function p.renderComponents( frame, payload)
    local args = frame.args
    
	-- 1. 载入 json 文件
    if not payload then
      payload = mw.loadJsonData( args["payload"] )
    end
    
    
    local text = ""
    for _, componentItem in ipairs(payload) do
      local tmplName, data = componentItem[1], componentItem[2]
      local tmplOptions = {}

      for key, value in pairs(data) do
        if type(value) == "table" and #value > 0 then
          tmplOptions[key] = p.renderComponents(args, value)
        else
          tmplOptions[key] = value
        end
      end
    end

    text = text .. frame:getParent():expandTemplate{
      title = args[tmplName],
      args = tmplOptions
    }

    return text
end


return p