Модуль:GetField: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| Строка 405: | Строка 405: | ||
local keyPath = args[3] or "" | local keyPath = args[3] or "" | ||
local tplPath = mw.text.unstripNoWiki(args[4] or "") | local tplPath = mw.text.unstripNoWiki(args[4] or "") | ||
local searchType = (args.searchType or ""):lower() | |||
if searchValue == "" or pagePath == "" or keyPath == "" or tplPath == "" then | if searchValue == "" or pagePath == "" or keyPath == "" or tplPath == "" then | ||
return "" | return "" | ||
end | |||
if searchType == "" then | |||
searchType = "value" | |||
end | end | ||
| Строка 419: | Строка 423: | ||
end | end | ||
local matches = find_matching_ids(idsTable, keyPath, searchValue) | local matches | ||
if searchType == "key" then | |||
local target = tostring(searchValue) | |||
matches = {} | |||
for idKey, entry in pairs(idsTable) do | |||
if type(entry) == "table" then | |||
local v = get_by_path(entry, keyPath) | |||
if type(v) == "table" and v[target] ~= nil then | |||
matches[#matches + 1] = idKey | |||
end | |||
end | |||
end | |||
else | |||
matches = find_matching_ids(idsTable, keyPath, searchValue) | |||
end | |||
if #matches == 0 then | if #matches == 0 then | ||