我有一个表,其列如下:
<Table id="table2" visibleRowCount="5" rows="{
path: '/ProductCollection',
sorter: {path: 'serialId', descending: false}}">
<columns>
<Column width="50px">
<m:Text text="Employee ID" />
<template>
<m:Text text="{employeeId}" wrapping="false" />
</template>
</Column>
<Column width="200px">
<m:Text text="EmployeeName" />
<template>
<m:Text text="{employeeName}" wrapping="false" />
</template>
</Column>
</columns>
</Table>
并且JSON数据为:
var oData = {
ProductCollection: [
{
employeeId: "1"
employeeName:"xyz"
},
{
employeeId: "1"
employeeName:"xyz"
},
{
employeeId: "1"
employeeName:"xyz"
}
]
};
而且我尝试将其绑定为:
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(ProductCollection);
this.getView().setModel(oModel);
我正在获取数据,但进入了模型,但是无法在表中显示获取空行的值。我在绑定(xml视图)时遇到问题,任何指导链接或解决方案都将非常有用,TIA
<mvc:View controllerName="reg.cmdd.Consumer.controller.Home" xmlns="sap.ui.table" xmlns:mvc="sap.ui.core.mvc" xmlns:u="sap.ui.unified"
xmlns:c="sap.ui.core" xmlns:m="sap.m" height="100%">
<m:Page showHeader="false" enableScrolling="false" class="sapUiContentPadding">
<m:content>
<Table id="table2" visibleRowCount="5" rows="{ path: '/ProductCollection', sorter: {path: 'serialId', descending: false}}">
<columns>
<Column width="50px">
<m:Text text="Employee ID"/>
<template>
<m:Text text="{employeeId}" wrapping="false"/>
</template>
</Column>
<Column width="200px">
<m:Text text="EmployeeName"/>
<template>
<m:Text text="{employeeName}" wrapping="false"/>
</template>
</Column>
</columns>
</Table>
</m:content>
</m:Page>
</mvc:View>
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function (Controller) {
"use strict";
return Controller.extend("reg.cmdd.Consumer.controller.Home", {
onInit: function () {
var oData = {
ProductCollection: [{
employeeId: "1",
employeeName: "xyz"
}, {
employeeId: "1",
employeeName: "xyz"
}, {
employeeId: "1",
employeeName: "xyz"
}
]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(oData);
this.getView().setModel(oModel);
}
});
});
您的代码很好,问题必须在其他地方
编辑:检查此行:
oModel.setData(ProductCollection);
应该是
oModel.setData(oData);