我无法将此数组拆分为两个单独的块。
'\0'
答案 0 :(得分:0)
使用JSON
脚本:
var json='array string'
var obj=JSON.parse(json)
var map1=obj[0]
var map2=obj[1]
现在你有map1
和map2
大括号内的数据。
您可以像JSON一样访问数据:
var val=map1.allowChildren//will return false
或者您可以使用以下命令转换回字符串:
var str=JSON.stringify(map1)
答案 1 :(得分:0)
/ * 您可以使用以下循环来迭代对象。 * /
var js_obj = [{
"allowChildren": false,
"allowDrag": false,
"allowDrop": false,
"cls": "resource-facility-group",
"disabled": false,
"draggable": false,
"editable": false,
"expandable": false,
"expanded": false,
"hidden": false,
"href": "",
"hrefTarget": "",
"icon": "",
"iconCls": "resource-facility-group",
"id": "RESFACCONT--1",
"leaf": false,
"onSelectFunc": "javascript:clearViewPanel()",
"qtip": "",
"qtipCfg": "",
"shortName": "_facilities",
"singleClickExpand": true,
"target": false,
"text": "Facilities & Classrooms"
}, {
"allowChildren": false,
"allowDrag": false,
"allowDrop": false,
"cls": "resource-contact-group",
"disabled": false,
"draggable": false,
"editable": false,
"expandable": false,
"expanded": false,
"hidden": false,
"href": "",
"hrefTarget": "",
"icon": "",
"iconCls": "resource-contact-group",
"id": "RESCONCONT--1",
"leaf": false,
"onSelectFunc": "javascript:clearViewPanel()",
"qtip": "",
"qtipCfg": "",
"shortName": "_contacts",
"singleClickExpand": true,
"target": false,
"text": "Contacts"
}];
for(var i in js_obj){
//alert(i);
for(var j in js_obj[i]){
console.log(js_obj[i][j]);
}
}
答案 2 :(得分:-1)
请尝试此
var o = [{"allowChildren":false,"allowDrag":false,"allowDrop":false,"cls":"resource-facility-group","disabled":false,"draggable":false,"editable":false,"expandable":false,"expanded":false,"hidden":false,"href":"","hrefTarget":"","icon":"","iconCls":"resource-facility-group","id":"RESFACCONT--1","leaf":false,"onSelectFunc":"javascript:clearViewPanel()","qtip":"","qtipCfg":"","shortName":"_facilities","singleClickExpand":true,"target":false,"text":"Facilities & Classrooms"},{"allowChildren":false,"allowDrag":false,"allowDrop":false,"cls":"resource-contact-group","disabled":false,"draggable":false,"editable":false,"expandable":false,"expanded":false,"hidden":false,"href":"","hrefTarget":"","icon":"","iconCls":"resource-contact-group","id":"RESCONCONT--1","leaf":false,"onSelectFunc":"javascript:clearViewPanel()","qtip":"","qtipCfg":"","shortName":"_contacts","singleClickExpand":true,"target":false,"text":"Contacts"}];
var arr = $.map(o, function(el) { return el; })