我有一个对象,它看起来是这样的:其子获取父在对象结构
{
"11": {
"id": 11,
"parent_product": 0,
"product_name": "WebStore",
"product_price_city": null,
"child": {
"12": {
"id": 12,
"parent_product": 11,
"product_name": "WebStore - Single",
"product_price_city": 500
},
"13": {
"id": 13,
"parent_product": 11,
"product_name": "WebStore - Full",
"product_price_city": 2500
}
}
}
}
这里,关键11
有两个孩子的:12
和13
。
在不同的对象,看起来像这样:
{
"316":
{
"id": 316,
"product_id": 13,
"sold_by": 1,
"product_price": 5000,
"subscription_month": 3,
"updated_by": 0,
"created_at": 1449573556
},
"317":
{
"id": 317,
"product_id": 12,
"sold_by": 1,
"product_price": 5000,
"subscription_month": 3,
"updated_by": 0,
"created_at": 1449573556
}
}
我这里的product_id是12或13,也就是它永远是个孩子。
我需要获得12和13的父ID,所以我可以访问他们的第一个对象。
data.11
如何在JavaScript中获得它?
你可以改变数据是如何组织/结构化或为这最后? – AlvaHenrik
每个孩子只有一个家长吗? –
@阿米尔:是的。每个孩子只有一个父母。 – nirvair