模块: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]
      text = text .. tmplName .. "=" .. args[tmplName] .. "<br>"
      
      local tmplOptions = {}

      for key, value in pairs(data) do

        if type(value) == "table" then
          tmplOptions[key] = p.renderComponents( frame, value )
        else
          tmplOptions[key] = value
        end

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

    return text
end


return p