最佳答案
与 问题来了类似,我正在寻找一种方法来搜索类似 JSON 的对象。
假设我的物体的结构是这样的:
TestObj = {
"Categories": [{
"Products": [{
"id": "a01",
"name": "Pine",
"description": "Short description of pine."
},
{
"id": "a02",
"name": "Birch",
"description": "Short description of birch."
},
{
"id": "a03",
"name": "Poplar",
"description": "Short description of poplar."
}],
"id": "A",
"title": "Cheap",
"description": "Short description of category A."
},
{
"Product": [{
"id": "b01",
"name": "Maple",
"description": "Short description of maple."
},
{
"id": "b02",
"name": "Oak",
"description": "Short description of oak."
},
{
"id": "b03",
"name": "Bamboo",
"description": "Short description of bamboo."
}],
"id": "B",
"title": "Moderate",
"description": "Short description of category B."
}]
};
我想得到一个 id = “ A”的对象。
我试过各种各样的方法,比如:
$(TestObj.find(":id='A'"))
但似乎没什么效果。
有没有人能想出一种方法来检索一个项目基于一些标准而不使用“每个”?