Ich möchte einzelne Json Objec basierend auf ID, von unten Baum zu finden. Beispiel - getObjeById(4)
,wie rekursiv spezifische Objektform Baum zu finden
es sollte Obj von unterhalb der Struktur zurückgeben. brauche Hilfe dabei.
data={
"mytree": {
"id": "dectree",
"dt": {
"choice": {
"id": 0,
"title": "Which color",
"description": "Choose color ?",
"choice": [
{
"id": 1,
"title": "Yellow",
"description": "Yellow ? ",
"choice": [
{
"id": 5,
"title": "Dark Yellow",
"description": "Dark Yellow ,
"choice": [
{
"id": 6,
"title": "id 6 yello",
"description": "<span> last leaf for yello </span>"
}]
},
{
"id": 4,
"title": "Light Yellow",
"description": "Light Yellow
}
]
},
{
"id": 2,
"title": "Red",
"description": "Red ?"
},
{
"id": 3,
"title": "Green",
"description": "Green
},
{
"id": 7,
"title": "white",
"description": "white color",
"choice": [
{
"id": 8,
"title": "id 8 white",
"description": "<span> last leaf for white </span>"
}]
}
]
}
}
}
}
Rekursiver Code ist sehr teuer. Kannst du deinen Baum nicht reorganisieren? –
Haben Sie diese Lösung ausprobiert? - http://stackoverflow.com/questions/10679580/javascript-search-inside-a-json-object –
Ich bin in Ordnung, wenn es andere Möglichkeit gibt, Objektform Baum zu finden. – user3215858