我无法让我的表列和行的动态绑定工作。
假设我有两个模型,一个包含表格列信息:
var aColumnData = [
{
columnId : "col1"
},
{
columnId : "col2"
},
{
columnId : "col3"
},
{
columnId : "col4"
},
{
columnId : "col5"
}
];
和一个数据:
var aData = [
{
col1 : "Row 1 col 1",
col2 : "Row 1 col 2",
col3 : "Row 1 col 3",
col4 : "Row 1 col 4",
col5 : "Row 1 col 5"
},
{
col1 : "Row 2 col 1",
col2 : "Row 2 col 2",
col3 : "Row 2 col 3",
col4 : "Row 2 col 4",
col5 : "Row 2 col 5"
}
];
然后我设置模型:
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({
columns : aColumnData,
rows : aData
});
然后我在视图中创建我的表:
var oTable = new sap.ui.table.Table();
var oColumnTemplate = new sap.ui.table.Column({
label : "{columnDesc}",
template : new sap.ui.commons.TextView().bindProperty("text", "<this_should_be_dynamic_but_how?>")
});
oTable.bindColumns("/columns", oColumnTemplate);
oTable.bindRows("/rows");
困扰我的部分是绑定到 TextView 模板中的当前列;这应该是动态的(“col1”、“col2”等)并且可以即时完成——这就是我假设的绑定——但我无法让它工作......
我想我错过了一些简单而微不足道的东西,但我现在有点迷失了......非常感谢任何帮助!
===============================
编辑:我通过遍历列数组并使用 addColumn() 方法让它工作:
jQuery.each(aColumnData, function(i, v) {
oTable.addColumn(new sap.ui.table.Column({
label : v.columnDesc,
template: new sap.ui.commons.TextView().bindProperty("text", v.columnId)
}));
});
...但我希望使用 bindColumns() / bindRows() 方法会有更清洁的方法: