我有这个JSON对象。
{
"headerContent": [
{
"name": "User Id",
"key": "userId",
"type": "text",
"default": "Enter User Id"
},
{
"name": "User Name",
"key": "userName",
"type": "text",
"default": "Enter User Name"
},
{
"name": "Password",
"key": "password",
"type": "password",
"default": "Enter Password"
},
{
"name": "Mobile Number",
"key": "mobileNumber",
"type": "text",
"default": "Enter Mobile Number"
},
{
"name": "User Category",
"key": "userCategory",
"type": "select",
"default": "Select Category",
"options" : ["Admin", "Client", "Regulator"]
},
{
"name": "E-Mail",
"key": "email",
"type": "text",
"default": "Enter Email"
},
{
"name": "User Access",
"key": "userAccess",
"type": "select",
"default": "Select User Access",
"options" : ["All", "Site"]
}
],
"bodyContent": [
{
"userId": "user_1",
"userName": "DemoUser",
"mobileNumber": "99999999",
"userCategory" : "Admin",
"email" : "demo@kl.com",
"userAccess" : "All"
}
]
}
headerContent
描述了bodyContent
的属性。
现在,默认情况下,对象中的所有数据(如user_1)都会在details
中显示。在html页面中,我有一个包含3个值[Admin,Client,Regulator]的选择框,它们是3个不同的用户类别。当我选择其中任何一个时,我想根据选择显示数据。
我的HTML页面包含一个选择框来选择类别。 <script src="JSCode.js"></script>
<select id='listSelect' onChange="updateList()">
<option value='' selected >All</option>
<option value='admin'>Admin</option>
<option value='client'>Client</option>
<option value='regulator'>Regulator</option>
</select>
<div id='details'> </div>
headerContent
中检查第五个数据(属性)。 - Nisfan