【发布时间】:2017-05-04 04:23:51
【问题描述】:
我想绑定图块菜单,但绑定选择有问题。我有一个 JSON 结构:
{
"module":{
"module":[
{
"id": "0",
"name": "Kepesertaan"
},
{
"id": "1",
"name": "Layanan dan Manfaat"
},
{
"id": "2",
"name": "Investasi"
},
{
"id": "3",
"name": "Perbendaharaan"
},
{
"id": "4",
"name": "Aktuaria"
}
],
"system":[
{
"id": "5",
"name": "Pengumuman"
}
]
}
}
控制器:
onInit: function(oEvent){
var oModel = new JSONModel("metroui/module.json");
this.getView().setModel(oModel);
},
pressTileModule : function(oEvent){
var sPath = oEvent.getSource().getBindingContext().getPath();
var oModel = this.getView().getModel();
var oContext = oModel.getProperty(sPath);
}
XML:
<core:View xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:tnt="sap.tnt"
controllerName="metroui.MetroUI"
xmlns:html="http://www.w3.org/1999/xhtml">
<App id="navCon">
<pages>
<Page id="module" showHeader="false">
<Panel headerText="Module">
<content>
<l:HorizontalLayout
id="TileContainerModule"
allowWrapping="true"
content="{/}">
<GenericTile class="sapUiTinyMarginBegin sapUiTinyMarginTop tileLayout"
header="{name}" press="pressTileModule">
<tileContent>
<TileContent>
<content>
<ImageContent description="{id}" src="sap-icon://list"/>
</content>
</TileContent>
</tileContent>
</GenericTile>
</l:HorizontalLayout>
</content>
</Panel>
</Page>
</pages>
</App>
</core:View>
对于绑定对象模块>模块(来自 JSON),在 XML 文件中的 content="{/module/module}" 中设置,但我想设置内容路径 JSON 在控制器中,因为我想设置条件绑定,有时我只想绑定模块>模块或绑定模块>系统(来自JSON结构)。加载 JSON 文件时如何绑定选择?如果我将 JSON 结构放在控制器中,我可以创建新的 JSON 模型 this.module.module 或 this.module.system 并在 XML 中设置 content="{/}",但是当我加载文件 JSON 时我无法选择绑定.如何解决这个问题?
谢谢, 鲍比
【问题讨论】:
标签: javascript json xml sapui5