我在观看json数组后制作了一个json数组。我面临一个问题,它在对象内部创建数组。但是我需要在父数组内部添加数组
我得到这个结果
[
{
"a": {
"commandList": [],
"testCaseList": []
},
"testCaseList": []
},
{
"b": {
"commandList": [],
"testCaseList": []
},
"testCaseList": [
{
"b-a-1": {
"commandList": [],
"testCaseList": []
},
"testCaseList": []
},
{
"b-b-2": {
"commandList": [],
"testCaseList": []
},
"testCaseList": []
}
]
},
{
"c-1": {
"commandList": [],
"testCaseList": []
},
"testCaseList": []
}
]
但是我需要把这个放出来
[
{
"a": {
"commandList": [
],
"testCaseList": [
]
},
},
{
"b": {
"commandList": [
],
"testCaseList": [
{
"b-a-1": {
"commandList": [
],
"testCaseList": [
]
},
},
{
"b-b-2": {
"commandList": [
],
"testCaseList": [
]
},
}
]
},
},
{
"c-1": {
"commandList": [
],
"testCaseList": [
]
},
}
]
我尝试更改此行
item.testCaseList = inputItem.children.map(mapItem);
改变
var obj= JSON.parse(sessionStorage.getItem(inputItem.id)
obj.testCaseList=inputItem.children.map(mapItem)
然后我得到了错误
这是我的小提琴
http://jsfiddle.net/tJ7Kq/2/
最佳答案
在您尝试更改的行中,使用
item[inputItem.id].testCaseList
代替
item.testCaseList
更新了Fiddle。
如果数据过于混乱,请尝试对其进行可视化处理。 http://jsonblob.com/