我試圖將一個完整的組合框與JSON視圖中的模板綁定。我將模型綁定到視圖,將它與我在控制器中創建的模板綁定是沒有問題的。但是,我怎麼才能在視圖中實現這一點?如何在JSON視圖中完整地綁定組合框
我面向自己在這個例子中,這是使用XML訪問量:http://scn.sap.com/thread/3689278
我不得不掩蓋和凝結的代碼,所以也許認爲心不是以這種形式 這裏是我的(濃縮)查看正常工作:
{
"Type": "sap.ui.core.mvc.JSONView",
"controllerName": "appname.controller.controllerName",
"height": "100%",
"width": "100%",
"content": [
{
"Type": "sap.m.Page",
"title": "Suche",
"content": [
{
"Type": "sap.ui.commons.ComboBox",
"id": "myCbo",
"maxPopupItems": 5,
"items": {
"path": "{ModelName>ItemsForMyCbo}",
"template": {
"Type": "sap.ui.core.ListItem"
"text": "{Value}",
"key": "{Key}",
"enabled": true,
"icon": "",
"additionalText": "",
}
}
}
]
}
]
}
這裏是我的模型:
screenModel : {
ItemsForMyCbo : [
{
Key : "1",
Value : "Val1"
},
{
Key : "2",
Value : "Val2"
},
{
Key : "3",
Value : "Val3"
}
]
}
和控制器的部分:
var oModel = new sap.ui.model.json.JSONModel()
oModel.setData(this.screenModel);
this.getView().setModel(oModel, "ModelName");
這並不是令人困惑的......該屬性已被稱爲'path',因此API期待正確的路徑,而不是在大括號之間寫入的東西。但在XML視圖中,你只有普通的字符串,沒有'path'屬性(你也可以在XML視圖中使用路徑,但那是另一回事)。所以他們想出了大括號來區分路徑和基本字符串。聽起來很直接。 – Marc