I built this JSON (tested as valid) (.. don't mind that men and women are named the same here :-)):
{
"staff": {
"berlin": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}],
"paris": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}],
"oslo": [{
"male": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
],
"female": [
{"firstName": "Lasse", "lastName": "Larsson"},
{"firstName": "Gerrit", "lastName": "Gartner"}
]
}]
}
}
In my controller I set the JSON model to the whole view like this:
// init instance of JSON model
this.staffData = new sap.ui.model.json.JSONModel();
// load JSON file into model
this.staffData.loadData("ajax-dummy/staff.json");
// bind model to whole view
this.getView().setModel(this.staffData);
In my XML view I would now like to dynamically build a (nested) DropdownBox which should make me select e.g. berlin->male->lastName So I need 3 levels of ListItems.
The first problem is: I could generate this with JS (build one Listitem for each key in the staff object etc.) but I have no idea how to deal with this in the XML view. It looks like this at the moment:
<content>
<DropdownBox id="dd-locations" editable="true">
<core:ListItem text="{/staff/berlin}"></core:ListItem>
</DropdownBox>
</content>
And it displays (of course) just "{object ..}" in den DropdownBox, because it IS an object.
Is this even possible to build within the XML view with data binding? Or is there a better way to structure the JSON? I know the ListItems need an array... And finally: How can I nest the ListItems? Is there a better Control then DropdownBox I should use?
EDIT: What I want to have is "just" nesting Listitems like I could in HTML. I tried e.g.:
<ComboBox>
<items>
<core:ListItem key="key2" text="text2"/>
<core:ListItem key="key3" text="text2">
<ComboBox>
<items>
<core:ListItem key="key4" text="text3"/>
<core:ListItem key="key5" text="text3"/>
<core:ListItem key="key6" text="text3"/>
</items>
</ComboBox>
</core:ListItem>
<core:ListItem key="key4" text="text2"/>
</items>
</ComboBox>
But hen an error occurs which says:
Uncaught Error: Cannot add direct child without default aggregation defined for control sap.ui.core.ListItem
How can I define an item aggregation for a ListItem? Would that work?
Thanks a lot, ho