我在元组中有一个表格列表,格式如下,当前页面为
CurrPageName = "ihtx_f_10_00_00_00_00_h210401".
FormList = {form_list, [{"IHTX_F_10_00_00_00_00_H210401",true},
{"IHTX_F_09_00_00_00_00_H210401",true},
{"IHTX_F_11_11_02_02_01_H220401",true},
{"IHTX_F_03_00_00_00_00_H210401",false},
{"IHTX_F_12_00_00_00_00_H211215",true},
{"IHTX_F_07_00_00_00_00_H210401",true},
{"IHTX_F_15_00_00_00_00_H210401",false},
{"IHTX_F_11_00_00_00_00_H210401",false},
{"IHTX_F_02_00_00_00_00_H210401",true},
{"IHTX_F_01_00_00_00_00_H240401",true}]}.
如何从FormList中找到CurrPageName?我尝试了list:keyfind,keysearch到内部列表,但总是返回false或者一些错误。如果CurrPageName存在且其值为true,则只应返回true else else。
我是二郎的新手。感谢
答案 0 :(得分:2)
该列表将页面名称存储为大写字符串,因此首先要确保您的CurrPageName
变量也包含大写字符串
CurrPageName = string:to_upper("ihtx_f_10_00_00_00_00_h210401").
然后提取元组列表并搜索页面
{form_list, L} = FormList, % Extract tuple list to L
KeyPosition=1, % The name we look for is at position 1 in the tuple
T=lists:keyfind(CurrPageName, KeyPosition, L),
case T of
{_Key, true} ->
true ;
false ->
false
end.
答案 1 :(得分:1)
您可以使用proplists。
CurrPageName = string:to_upper("ihtx_f_10_00_00_00_00_h210401").
{form_list, L} = FormList,
Res = proplists:is_defined(CurrPageName, L)