我有以下代码
oTableEntry = this.getView().byId("oTable");
var count = oTableEntry._getRowCount();
var oTData;
for (var i = 0; i < count; i++) {
oTData = oTableEntry.getContextByIndex(i).getObject();
oTData
并不包含所有列的值,即使它们出现在表中也是如此。我在这里做错什么了吗?
答案 0 :(得分:2)
我认为您正在尝试获取每一行的表列及其值。这是您可以执行的操作:
var oTable = this.getView().byId("oTable");//Get the table by Id
var aItems = oTable.getAggregation("items");//get the items of the table
for (var i=0; i<aItems.length; i++) {
var tableColumns = aItems[i].getAggregation("cells"); //Here tableColumns will //have all the columns of the table rows.
var column1Value = tableColumns[1].getProperty("text");
}
答案 1 :(得分:2)
希望您正在寻找相同的解决方案!
var oTable = sap.ui.getCore().byId("YourTableID");
if (oTable) {
var oColumns = oTable.getColumns();//get all columnms
var oRows = oTable.getItems();
for (var r in oRows) {
var oRow = oRows[r];
console.log(oRow.getBindingContext().getObject());//return the row data
}
}