[英]Setting data to JSON model, and then setting that model to a table in SAPUI5
Here is my JSON object (validated at JSONlint.com): 这是我的JSON对象(已在JSONlint.com上验证):
[
{
"team": "xxx",
"fname": "0",
"lname": "C5042439"
},
{
"team": "yyy",
"fname": "0",
"lname": "C5067631"
}
]
I followed this tutorial: http://scn.sap.com/docs/DOC-46156 我遵循了本教程: http : //scn.sap.com/docs/DOC-46156
In my model I ended up having: 在我的模型中,我最终遇到了:
var oTable = new sap.ui.table.Table({
title: "Employee Details", // Displayed as the heading of the table
visibleRowCount: 3, // How much rows you want to display in the table
selectionMode: sap.ui.table.SelectionMode.Single, //Use Singe or Multi
navigationMode: sap.ui.table.NavigationMode.Paginator, //Paginator or Scrollbar
fixedColumnCount: 3, // Freezes the number of columns
enableColumnReordering:true, // Allows you to drag and drop the column and reorder the position of the column
width:"1024px" // width of the table
});
// Use the Object defined for table to add new column into the table
oTable.addColumn({
label: new sap.ui.commons.Label({text: "Team"}), // Creates an Header with value defined for the text attribute
template: new sap.ui.commons.TextField().bindProperty("value", "team"), // binds the value into the text field defined using JSON
sortProperty: "team", // enables sorting on the column
filterProperty: "team", // enables set filter on the column
width: "125px" // width of the column
});
oTable.addColumn({
label: new sap.ui.commons.Label({text: "FName"}),
template: new sap.ui.commons.TextField().bindProperty("value", "fname"),
sortProperty: "fname",
filterProperty: "fname",
width: "125px"
});
oTable.addColumn({
label: new sap.ui.commons.Label({text: "Lname"}),
template: new sap.ui.commons.Link().bindProperty("text", "lname"),
sortProperty: "lname",
filterProperty: "lname",
width: "200px"
});
var vData =
[
{
"team": "xxx",
"fname": "0",
"lname": "C5042439"
},
{
"team": "yyy",
"fname": "0",
"lname": "C5067631"
}
];
var oModel = new sap.ui.model.json.JSONModel(); // created a JSON model
oModel.setData({modelData: vData}); // Set the data to the model using the JSON object defined already
oTable.setModel(oModel);
oTable.bindRows("/modelData"); // binding all the rows into the model
//Initially sort the table
oTable.sort(oTable.getColumns()[0]);
oTable.placeAt("table");
My question is how would I bind that JSON model to the table so that it displays the data within the model? 我的问题是如何将JSON模型绑定到表,以便在模型中显示数据? at the moment am getting this error: Uncaught Error: "[object Object]" is not valid for aggregation "columns" of Element sap.ui.table.Table#__table0
目前正在收到此错误: 未捕获的错误:“ [对象对象]”对于元素sap.ui.table.Table #__ table0的聚合“列”无效
From my understanding there is something wrong with binding the columns to the actual data, but I'm not sure. 根据我的理解,将列绑定到实际数据有一些问题,但是我不确定。 Any help will be appreciated.
任何帮助将不胜感激。
You are adding indeed an object to your table instead of a column -- oTable.addColumn()
expects an object of type sap.ui.table.Column
您确实在向表中添加了一个对象,而不是向列添加了一个对象
oTable.addColumn()
需要一个sap.ui.table.Column
类型的对象
Change your code to: 将您的代码更改为:
oTable.addColumn(new sap.ui.table.Column({
label: new sap.ui.commons.Label({text: "Lname"}),
template: new sap.ui.commons.Link().bindProperty("text", "lname"),
sortProperty: "lname",
filterProperty: "lname",
width: "200px"
}));
etc. 等等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.