在这里工作演示:http: //jsfiddle.net/8Q4Lf/3/
我正在检索json上的数组并将其存储在一个隐藏input
的函数中:
$.post("http://"+ document.domain + baseUrl + "/tickets/getCategoryDepartmentRelation/",
function(dat){
$('#departmentsByCategory_array').val(JSON.stringify(dat));
});
调用返回此值:
{
"Investigation Request": [
"Client server",
"Interface",
"Engine"
],
"Configure Planning": [
"Interface",
"Engine"
],
"Bug Report": [
"Client server",
"Interface",
"Engine",
"Database"
],
"Development Request": [
"Interface",
"Dev Management",
"Database",
"Client server",
"Engine"
],
"Suggestion Box": [
"Dev Management"
],
"Post Site Feedback": [
"Web"
]
}
这是json
这个数组的表示:
Array
(
[Investigation Request] => Array
(
[0] => Client server
[1] => Interface
[2] => Engine
)
[Configure Planning] => Array
(
[0] => Interface
[1] => Engine
)
[Bug Report] => Array
(
[0] => Client server
[1] => Interface
[2] => Engine
[3] => Database
)
[Development Request] => Array
(
[0] => Interface
[1] => Dev Management
[2] => Database
[3] => Client server
[4] => Engine
)
[Suggestion Box] => Array
(
[0] => Dev Management
)
[Post Site Feedback] => Array
(
[0] => Web
)
)
这input
用以下数据填充:
<input type="hidden" name="demo" value="{"Investigation Request":["Client server","Interface","Engine"],"Configure Planning":["Interface","Engine"]," Bug Report":["Client server","Interface","Engine","Database"]," Development Request":["Interface","Dev Management","Database","Client server","Engine"],"Suggestion Box":["Dev Management"],"Ticket Site Feedback":["Web"]}" id="departmentsByCategory_array">
我可以用这个得到完整的数组:
$('#departmentsByCategory_array').val();
但我试图只检索一个元素的值,例如"Configure Planning"。
如何在 Javascript 或 jQuery 中使用这些值?(循环,比较...)