与brnwdrng的问题类似,我正在寻找一种方法来搜索类似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'"))
但是似乎什么都不起作用。
有没有人想到一种根据某些条件检索项目的方法,而不使用“each”?