OpenUI5 Treetable:获取选定的行及其模型数据
OpenUI5 Treetable: get selected rows and their model data
几个小时以来,我一直在尝试获取树中选定行的模型数据 table。
我用了这个例子:https://openui5.hana.ondemand.com/#/sample/sap.ui.table.sample.TreeTable.JSONTreeBinding/preview
此外,我将 sortProperty 和 filterProperty 添加到列中。到目前为止一切正常。
我想做的是通过所有选定行的 ajax 提交 json 数据。为此,我需要获取所选行的 json 数据。
我尝试了什么:
var oTable = this.getView().byId("tableName").getSelectedIndicies()
然后
for(var i=0; i<=oTable.length; i++) {
this.getView().byId("tableName").getModel().getData().jobs[oTable[i]]
}
好像我用sorter和filter功能的时候,指标都不对了。索引键不会改变。
知道如何解决我的请求吗?提前谢谢!
您可以做一些小改动,以便在 for 循环中获取正确的数据。
- 获取根据索引信息选择的item的bindingContext。
var sPath = TreeTable.getRows()[0].getBindingContext()
- 从模型中获取数据为:
oTreeTable.getModel().getProperty(sPath)
我是这样解决的:
var oJSON = {};
var aData = [];
var oTable = this.getView().byId("TreeTable");
var aIndicies = oTable.getSelectedIndices();
var oSelect = this.getView().byId("selectStandort").getSelectedKey();
for (var i=0; i<aIndicies.length; i++) {
var oTableContext = oTable.getContextByIndex(aIndicies[i]);
var rowData = oTable.getModel("jobs").getProperty(oTableContext.getPath());
aData.push(rowData);
}
oJSON.jobs = aData;
oJSON.standort = oSelect;
几个小时以来,我一直在尝试获取树中选定行的模型数据 table。
我用了这个例子:https://openui5.hana.ondemand.com/#/sample/sap.ui.table.sample.TreeTable.JSONTreeBinding/preview
此外,我将 sortProperty 和 filterProperty 添加到列中。到目前为止一切正常。
我想做的是通过所有选定行的 ajax 提交 json 数据。为此,我需要获取所选行的 json 数据。
我尝试了什么:
var oTable = this.getView().byId("tableName").getSelectedIndicies()
然后
for(var i=0; i<=oTable.length; i++) {
this.getView().byId("tableName").getModel().getData().jobs[oTable[i]]
}
好像我用sorter和filter功能的时候,指标都不对了。索引键不会改变。
知道如何解决我的请求吗?提前谢谢!
您可以做一些小改动,以便在 for 循环中获取正确的数据。
- 获取根据索引信息选择的item的bindingContext。
var sPath =
TreeTable.getRows()[0].getBindingContext()
- 从模型中获取数据为:
oTreeTable.getModel().getProperty(sPath)
我是这样解决的:
var oJSON = {};
var aData = [];
var oTable = this.getView().byId("TreeTable");
var aIndicies = oTable.getSelectedIndices();
var oSelect = this.getView().byId("selectStandort").getSelectedKey();
for (var i=0; i<aIndicies.length; i++) {
var oTableContext = oTable.getContextByIndex(aIndicies[i]);
var rowData = oTable.getModel("jobs").getProperty(oTableContext.getPath());
aData.push(rowData);
}
oJSON.jobs = aData;
oJSON.standort = oSelect;