无法启用行选择按钮

问题描述 投票:0回答:1

想法是在选择一行时启用按钮。但是当我选择任何行时,按钮都不会启用。

请查看随附的代码段和屏幕截图[error_1]

     onInit: function () {
        var oViewModel,
            iOriginalBusyDelay,
            oTable = this.byId("table");

        // Put down worklist table's original value for busy indicator delay,
        // so it can be restored later on. Busy handling on the table is
        // taken care of by the table itself.
        iOriginalBusyDelay = oTable.getBusyIndicatorDelay();
        // keeps the search state
        this._aTableSearchState = [];

        this.oSemanticPage = this.byId("page");
        this.oEditAction = this.byId("editAction");
        oTable.attachSelectionChange(this.onTableSelection, this);
    },

    /* =========================================================== */
    /* event handlers                                              */
    /* =========================================================== */
    onTableSelection: function () {
        var oTable = this.getView().byId("table");
        var aSelectedItems = oTable.getSelectedItems();

        if (aSelectedItems.length > 0) {
            this.byId("test").setEnabled(true);
        }
javascript button odata sapui5 sapui5-smarttable
1个回答
0
投票

建议不要获取Button并操纵其enable / disable属性。尝试使用模型并相应地更改model属性。这就是MVC的工作方式。

    selectionChange: function() {
      oModel.setProperty("/btnEnabled", this.getSelectedItems().length > 0);
    }

演示:https://jsbin.com/rexeyaf/edit?js,output

© www.soinside.com 2019 - 2024. All rights reserved.