I need to traverse this data structure to render a set of lists. With a structure where nested data has the same structure as parent, it would be no problem - but here all models are different. There will be one list where each item contains a list of each level in this structure. Like so:
Desired result:
Unselected
| Countries | Provinces | Cities | <--- Top ul
---------------------------------------
|-China | | | <--- Sub uls
|-Denmark | | |
Selected
| Countries | Provinces | Cities |
---------------------------------------
|-China X |-Matjii X |- Go Neng |
|-Denmark |-Pausiu |- Tsau Pei X |
The Xs represent a selected option. If an item is selected, only it's information should be shown in subsequent lists. As you see above, since China is selected, the following lists have no data from Denmark shown.
Data structure:
{
countries: {
china: {
name: "China",
provinces: {
matjii: {
name: "Matjii",
cities: {
goneng: {
name: "Go Neng"
},
tsauPei: {
name: "Tsau Pei"
}
}
},
pausiu: {
name: "Pausiu",
cities: {...}
}
}
},
denmark: {
name: "Denmark",
counties: {
borjskada: {
name: "Borjskada",
towns: {
fjollmaska: {
name: "Fjollmaska"
}
}
},
larvmauda: {
name: "Larvmauda",
towns: {
tarnaby: {
name: "Taernaby"
}
}
}
}
}
}
}
I've tinkered with two different recursive approaches, but what stops me is always that I can not anticipate what the next level might be called (city, town or matjii).
Am I missing some simple obvious solution? Pseudo code is fine, I'm looking for a general approach to this.

Object.keys()counties, programmatically you don't want to touch that.