我已经找了一些数据,如:过滤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