mon*_*cht 2 javascript xml sapui5
在使用JS-Views时,在SAPUI5中为表或某事物分配模型或数据绑定非常容易.但是,在使用XML-Views时,我该怎么做呢?
<?xml version="1.0" encoding="UTF-8" ?>
<core:View
xmlns:core="sap.ui.core"
xmlns="sap.ui.commons"
xmlns:table="sap.ui.table"
xmlns:html="http://www.w3.org/1999/xhtml"
controllerName="view.Main">
<Panel text="Hello World from an XML view">
<Button text="Button" press="doSomething"></Button>
<table:Table width="100%" visibleRowCount="5" selectionMode="Single" editable="false">
<table:title><Label text="Wochentage"></Label></table:title>
<table:Column>
<Label text="ID" />
<table:template><TextField value="{id}"></TextField></table:template>
</table:Column>
</table:Table>
</Panel>
</core:View>
Run Code Online (Sandbox Code Playgroud)
我不想给表一个修复id属性并通过调用实现它
sap.ui.getCore().getElementById("idProductsTable").setModel(
demoJSONModel);
Run Code Online (Sandbox Code Playgroud)
在控制器...... :(
您通常会在控件中的控件(直接表或其父项之一)上设置模型.因此,我将假设您对初始语句的后半部分感到疑惑:"在使用XML-Views时将数据绑定分配给表...".
您所要做的就是将聚合表示为XML属性.所以如果你的demoJSONModel看起来像这样:
var demoJSONModel = new sap.ui.model.json.JSONModel({
data : [
{ id : 42 },
{ id : 1.618 },
{ id : 3.14 }
]
});
Run Code Online (Sandbox Code Playgroud)
那么你可以设置表的'rows'聚合的绑定,如下所示:
<table:Table
width="100%"
visibleRowCount="5"
selectionMode="Single"
editable="false"
rows="{/data}">
Run Code Online (Sandbox Code Playgroud)