-1
我有一个数组和其中的许多对象。我希望能够运行每个功能,在每个subpage > file
节点中每files/a
更换files/and
。我怎样才能做到这一点与适当的每个或循环功能?我想到了这一点,这是我脑海中的结构,看起来像可怕的解决方案。为许多子节点运行每个函数的正确方法是什么?
$.each(main, function(index, value) {
$.each(index.subpage, function(index, value) {
$.each(index.files, function(index, value) {
value.replace("files/a", "files/and");
});
});
});
主对象如下所示。
{
"main": [
{
"title": "AAA",
"hash": "a",
"subpage": [
{
"title": "b",
"hash": "b",
"subpage": [
{
"title": "c",
"hash": "c",
"subpage": [],
"files": [
{
"files/a/b/c/01_clandestino_dev%20%282%29.jpg": {}
},
{
"files/a/b/c/01_clandestino_dev%20%283%29.jpg": {}
}
],
"content": "",
"layout": "standart"
}
],
"files": [
{
"files/a/b/01_clandestino_dev%20%282%29.jpg": {}
},
{
"files/a/b/01_clandestino_dev%20%283%29.jpg": {}
}
],
"content": "asd123",
"layout": "standart"
}
],
"files": [
{
"files/a/01_clandestino_dev.jpg": {}
},
{
"files/a/01.Creative_Collective_Effect_Overview.jpg": {}
},
{
"files/a/01.Bor%C3%A5s_H%C3%B6gskola_Website_Narrow.jpg": {}
}
],
"content": "AAAb",
"layout": "standart",
"menuItem": "true"
}
]
}
可能欺骗http://stackoverflow.com/questions/2203958/jquery-recursive-iteration-over-objects – DLeh 2014-11-21 21:24:03
数据结构似乎很奇怪。您正试图修改值,但所有文件名都显示为对象键不是值 – charlietfl 2014-11-21 21:30:46
我想我必须在添加重命名之前删除文件名。 – kastelli 2014-11-21 21:37:59