我创建了一个SAPUI5表,我试图从按钮点击的行中获取元素, 例如:我的表有4行, 我需要获取第1列和第2列值,并在进行一些计算后将它们设置在第3列和第4列中, 我的表中也有一个下拉列表,我自定义绑定表中的下拉控件, 现在,当我在计算后重新绑定表时,我的下拉绑定将被删除。
下面是我的代码SAPUI5视图代码,
<t:Table rows="{/}">
<t:extension>
<OverflowToolbar>
<ToolbarSpacer />
<Button
icon="sap-icon://add"
press=".onAddPress"
/>
<Button
icon="sap-icon://add"
press=".onCalculate"
/>
</OverflowToolbar>
</t:extension>
<t:columns>
<t:Column>
<Text text="Item 1" />
<t:template>
<ComboBox width="100%" items="{items1}">
<core:Item
key="{key}"
text="{text}"
/>
</ComboBox>
</t:template>
</t:Column>
<!-- ... -->
</t:columns>
</t:Table>
这是我添加行的控制器代码,
onAddPress: function() {
var model = this.getOwnerComponent().getModel();
var currentRows = model.getProperty("/");
var newRows = currentRows.concat(this.createEntry());
model.setProperty("/", newRows);
},
我从以下链接获取帮助:https://plnkr.co/edit/8YvXxk?p=preview
下面是我的计算和重新绑定表的代码,
var oModel = this.getModel();
var oTable = this.getView().byId("tbl_lineItemsList");
var data = oTable.getModel();
var len = oTable._iBindingLength;
if (this._oViewModel.getProperty("/mode") === "create") {
for (var i = 0; i < len; i++) {
var _qty = data.oData[i].Quan;
var _mtnr = data.oData[i].Matnr;
if (_mtnr === '' || _qty === '') {
Flag = true;
message = " Material or Quantity, " + message;
break;
}
matnr[i] = data.oData[i].Matnr;
qty[i] = data.oData[i].Quan;
tfilters.push(new sap.ui.model.Filter("Matnr", sap.ui.model.FilterOperator.EQ, matnr[i]));
tfilters.push(new sap.ui.model.Filter("Quan", sap.ui.model.FilterOperator.EQ, qty[i]));
}
var mParameters = {
filters: tfilters,
success: function(oData) {
this.getModel("appView").setProperty("/busy", false);
if (oData.results["0"].Mesg === '') {
var oModel1 = new sap.ui.model.json.JSONModel(oData.results);
if (this._oViewModel.getProperty("/mode") === "create") {
oTable.unbindColumns();
oTable.unbindRows();
oTable.setModel(oModel1);
oTable.bindRows("/");
}
}
oModel.read("/TableSet", mParameters);