我创建了xml视图和控制器来绑定数据。 我没有看到任何数据。 我错过了什么吗?
<sap.ui.core.mvc:View controllerName="view.weeklyTasks"
xmlns="sap.m"
xmlns:sap.ui.core="sap.ui.core"
xmlns:sap.ui.core.mvc="sap.ui.core.mvc">
<Page title="Title">
<content>
<Table id="idProductsTable" noDataText="No data" items="{path: '/modelData'}" >
<columns>
<Column>
<Text text="Product" />
</Column>
<Column>
<Text text="Supplier" />
</Column>
</columns>
<items>
<ColumnListItem counter="0">
<cells>
<Text text="{name}"></Text>
<Text text="{date}"></Text>
</cells>
</ColumnListItem>
</items>
<headerToolbar>
<Toolbar>
<content>
<Label text="Weekly Tasks"></Label>
</content>
</Toolbar>
</headerToolbar>
</Table>
</content>
</Page>
</sap.ui.core.mvc:View>
sap.ui.controller("view.weeklyTasks", {
onInit: function() {
var aData = { modelData : [
{name: "Peter", date: "01012010"},
{name: "Petra", date: "01012011"},
{name: "Thomas", date: "01012012"},
{name: "John", date: "01012013"},
{name: "Maria", date: "01012014"}
]};
var oModel = new sap.ui.model.json.JSONModel(aData);
this.getView().setModel(oModel);
}
});
答案 0 :(得分:3)
好的,现在我可以让事情奏效。
1 - 将以下参数添加到您的bootstap
data-sap-ui-xx-bindingSyntax="complex"
有关data-sap-ui-xx-binding的更多信息语法:
Data Modeling for controls using XML views(SAPUI5)
SAP Help - SAPUI5 Configuration Options
2 - 您的观点还可以
<Page title="Title">
<content>
<Table id="idProductsTable" noDataText="No data" items="{path: '/modelData'}" >
<columns>
<Column>
<Text text="Product" />
</Column>
<Column>
<Text text="Supplier" />
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text="{name}"></Text>
<Text text="{date}"></Text>
</cells>
</ColumnListItem>
</items>
</Table>
</content>
</Page>
3 - 更新固定JSON格式的控制器
onInit: function() {
var aData = { "modelData" : [
{"name": "Peter", "date": "01012010"},
{"name": "Petra", "date": "01012011"},
{"name": "Thomas", "date": "01012012"},
{"name": "John", "date": "01012013"},
{"name": "Maria", "date": "01012014"}
]};
var oModel = new sap.ui.model.json.JSONModel(aData);
this.getView().setModel(oModel);
// OR sap.ui.getCore().setModel(oModel);
}
答案 1 :(得分:0)
我希望绑定控制器中的items属性,以便它可以动态更改,我将如何执行此操作?
我想它会像oTable.items = "{odataURL}"
如果硬编码,我的网址当前有效,但我不知道如何在控制器中获得相同的结果.js
答案 2 :(得分:0)
As per Question asked there is no need to make change in JSON format .
Normally we use Complex Binding when we have formatter/sorter or path added
we can achieve above result in other way also
just remove **path** from item and remove **data-sap-ui-xx-bindingSyntax="complex"** in index.html
<Table id="idProductsTable" noDataText="No data" items="{/modelData}">
<columns>
<Column>
<Text text="Product" />
</Column>
<Column>
<Text text="Supplier" />
</Column>
</columns>
<items>
<ColumnListItem >
<cells>
<Text text="{name}"></Text>
<Text text="{date}"></Text>
</cells>
</ColumnListItem>
</items>
</Table>