<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Dict</title>
</head>
<body>
</body>
<!--测试字典功能-->
<script>
const dictJsonStr = {
"agentType": [
{
"key": "1",
"name": "律师代理"
},
{
"key": "2",
"name": "公民代理"
}
],
"commission": [
{
"key": "123456",
"name": "广州仲裁委员会"
}
],
"litigantType": [
{
"key": "1",
"name": "申请人"
},
{
"key": "2",
"name": "被申请人"
},
{
"key": "3",
"name": "第三人"
}
]
};
function getDictName(dict, key){
childDict = dictJsonStr[dict];
for (i=0;i<childDict.length;i++){
if(childDict[i].key == key) {
return childDict[i];
}
}
}
getDictName("litigantType", 3).name;//可直接用此方法进行查询
console.log("字典",dictJsonStr,dictJsonStr["litigantType"]);
console.log("字典2",dictJsonStr,dictJsonStr.litigantType);
console.log("字典查询",getDictName("litigantType", 3).name)
</script>
</html>