gpt4 book ai didi

javascript - SAP UI5 - 无法从表中删除选定的行

转载 作者:行者123 更新时间:2023-11-30 08:47:53 26 4
gpt4 key购买 nike

我有一个 View ,其中包含一个具有单选模式的表格,其工具栏中有一个用于删除所选行的按钮。

虽然当我按下按钮时,它会删除所有行。

我的代码:

查看文件:

<template data-controller-name="myapplication.myview2">
<div data-sap-ui-type="sap.ui.table.Table" id="tb1" data-width="100%" data-title="Person Table"></div>
</template>

Controller 文件:

onInit: function() {
try {
var oTab = [
// the table content

];
var oToolbar = new sap.ui.commons.Toolbar();
oToolbar.addItem(new sap.ui.commons.Button({text: "Delete selected row",
press: function() {
try {
var newTab = this.getParent().getParent();
var index = newTab.getSelectedIndex();
if (index == -1)
alert("No row selected");
else {
var currModel = newTab.getModel();
var selectedRow = newTab.getRows()[index];
newTab.removeRow(selectedRow);
currModel.setData({table: newTab});
newTab.bindRows("/table");
}
} catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
}}));
this.byId("tb1").setToolbar(oToolbar);
this.byId("tb1").setVisibleRowCount(5);
this.byId("tb1").setNavigationMode(sap.ui.table.NavigationMode.Paginator);

// Columns definition should be HERE

var oModel = new sap.ui.model.json.JSONModel();
oModel.setData({table: oTab});
this.byId("tb1").setModel(oModel);
this.byId("tb1").bindRows("/table");

} catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
},
// More functions....

有什么想法吗?

最佳答案

您需要从模型中删除行,而不是直接从表中删除行。

关于javascript - SAP UI5 - 无法从表中删除选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20394996/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com