我已經找了一些數據,如:過濾JSON對象
var items = [
{ "id" : 1,
"title" : "this",
"groups" : [
{"id" : 1,
"name" : "groupA"},
{"id" : 2,
"name" : "groupB"}
]
},
{ "id" : 2,
"title" : "that",
"groups" : [
{"id" : 1,
"name" : "groupA"},
{"id" : 3,
"name" : "groupC"}
]
},
{ "id" : 3,
"title" : "other",
"groups" : [
{"id" : 3,
"name" : "groupC"},
{"id" : 2,
"name" : "groupB"}
]
}]
我想根據羣ID過濾,但我有麻煩甚至訪問他們 - item.group回報整個對象和其他任何事情(例如item.groups.id)都返回一個null或未定義的值。
有關如何做到這將是偉大的任何幫助。基本上我想過濾數組以包含特定組中的所有項目。
感謝
壞的數據結構。你不應該在每個'item.groups'數組中有組信息。組應該有一個單獨的數組或者是地圖和'item.groups'數組應該只有該組的索引,或者引用到組項目。這將減少JSON的大小,並使數據更容易管理。 – Blindman67