메뉴 건너뛰기

SAP 한국 커뮤니티

       

sap.ui.define([

    "ea/zcertemp/controller/BaseController",

    "sap/m/MessageToast",

    "sap/m/MessageBox"

],

 

    function (BaseController, MessageToast, MessageBox,) {

 

 

....

 

 

       onDelete: function (){
            var oTable = this.getView().byId("ST_table").getTable();
            var aSelectedItems = oTable.getSelectedItems();

            if (aSelectedItems.length === 0) {
                MessageBox.warning("삭제할 항목을 하나 이상 선택하세요.");
                return;
            }

            var aPaths = aSelectedItems.map(function(oItem) {
                return oItem.getBindingContext().getPath();
            });

            MessageBox.confirm("선택한 항목을 삭제하시겠습니까?", {
                actions: [MessageBox.Action.YES, MessageBox.Action.NO],
                onClose: function (sAction) {
                    if (sAction === MessageBox.Action.YES) {
                        this._deleteSelectedItems(aPaths);
                    }
                }.bind(this)
            });
        },

        _deleteSelectedItems: function (aPaths) {
            var oModel = this.getView().getModel();
            var bErrorOccurred = false;

            aPaths.forEach(function(sPath) {
                oModel.remove(sPath, {
                    success: function() {
                         MessageToast.show("모든 항목이 성공적으로 삭제되었습니다.");
                    },
                    error: function() {
                        if (!bErrorOccurred) {
                            bErrorOccurred = true;
                            MessageBox.error("삭제하는데 실패하였습니다.");
                        }
                    }
                });
            }); 

        }