我建這個JSON例子(測試爲有效)(..不介意,男人和女人的命名同樣在這裏:-)):SAPUI5複雜的數據綁定與DropdownBox在XML視圖
{
"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"}
]
}]
}
}
在我的控制器我設置了JSON模式的全貌是這樣的:
// 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);
在我的XML視圖現在,我想動態構建(嵌套)DropdownBox 這應該讓我選擇,例如, berlin-> male-> lastname 所以我需要3個級別的ListItems。
第一個問題是:我可以用JS生成這個(爲工作人員對象中的每個 鍵創建一個Listitem),但我不知道如何在XML視圖中處理這個問題。 它看起來像這樣的時刻:
<content>
<DropdownBox id="dd-locations" editable="true">
<core:ListItem text="{/staff/berlin}"></core:ListItem>
</DropdownBox>
</content>
並顯示(當然)剛剛「{對象..}」在書房DropdownBox,因爲它是一個對象。
這甚至可以在數據綁定的XML視圖內構建嗎?或者有沒有更好的方法來構建JSON的 ?我知道ListItems需要一個數組...最後:我如何嵌套ListItems?有沒有更好的控制 然後DropdownBox我應該使用?
編輯: 我想要的是「只」嵌套Listitems像我可以在HTML中。我試過例如: -
<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>
但母雞發生錯誤,它說:
Uncaught Error: Cannot add direct child without default aggregation defined for control sap.ui.core.ListItem
我如何定義一個列表項的項目聚集?這會起作用嗎?
非常感謝,豪
感謝你的建議 - 理論上這可能是一個選項,但我想探索使用dDropdownBox/ComboBox的可能性。 (我按問題編輯得更清楚我想要什麼) – 2015-02-13 09:02:49
查看我更新的答案以獲得可能的解決方案 – Qualiture 2015-02-13 10:04:29
非常感謝您爲我提供的啓發。這正是我從邏輯上看待的。大。最後,你的方法(更新依賴選擇)比嵌套元素更「優雅」。 – 2015-02-13 10:29:10