Я делаю массив 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
Обновлен скрипт.
Попробуйте визуализировать данные, если они становятся слишком грязными. http://jsonblob.com/