为什么setBusy不能在控制器内部工作?

时间:2019-09-11 13:04:51

标签: javascript sapui5

我正在尝试使用setBusy()将对话框设置为繁忙,但在我的控制器中无法正常工作。我在chrome develper工具控制台中使用setBusy(),它工作正常。当我尝试单击两次对话框时,也会出现错误。这是错误消息:

XMLTemplateProcessor-dbg.js:98 Uncaught Error: Error: adding element with duplicate id 'inactivedialog'
    at onDuplicate (Element-dbg.js:169)
    at f.register (ManagedObjectRegistry-dbg.js:44)
    at ManagedObject-dbg.js:528
    at f.constructor (ManagedObject-dbg.js:558)
    at f.constructor (Element-dbg.js:151)
    at f.constructor (Control-dbg.js:172)
    at new f (Metadata-dbg.js:463)
    at a1 (XMLTemplateProcessor-dbg.js:1063)
    at XMLTemplateProcessor-dbg.js:1070
    at SyncPromise-dbg.js:308

这是我在控制器中的代码。

var oView = this.getView();
Fragment.load({
        name: "ariba.so.kaakbatransfer.view.InactiveEmployee",
        controller: this
  }).then(function (oDialog) {
        oView.addDependent(oDialog);
        oDialog.open();
  }.bind(this));
var inactiveDialog = sap.ui.getCore().byId("inactivedialog");
inactiveDialog.setBusy(true);
$.ajax({
    url: "private",
    type: "GET",
    contentType: "application/json",
    success: function (data) {
        this.setModel(new JSONModel(data), "inactiveemployee");
    }.bind(this),
    error: function (e) {
        var bCompact = 
        !!this.getView().$().closest(".sapUiSizeCompact").length;
        MessageBox.error(
            "Data error. Please correct and try again. Refresh the page, if needed.", {
            styleClass: bCompact ? "sapUiSizeCompact" : ""}
         );
     } 
});
inactiveDialog.setBusy(false);

这是我的片段代码。

<core:FragmentDefinition id="inactivefragment" xmlns="sap.m" xmlns:core="sap.ui.core">
    <SelectDialog id = "inactivedialog" noDataText="No Employees Found" title="Select Employee" search="handleSearch" confirm="InactiveEmployeeClose"
        cancel="InactiveEmployeeClose" showClearButton="false"
        items="{path :'private', sorter:{ path : 'name', descending : false }}">
        <StandardListItem title="{private}" info="{private}" type="Active"/>
    </SelectDialog>
</core:FragmentDefinition>

运行ajax调用时,非活动对话框应该很忙。我应该能够在控制器中做到这一点。

1 个答案:

答案 0 :(得分:0)

对于具有重复ID的错误:

当您第一次单击按钮时,它会向视图添加Fragement(其ID应该是唯一的)。当您再次单击该按钮时,它将尝试再次执行该操作,但是该ID已经存在。为了防止这种检查,如果您的片段已经存在:

   onBtnPress: function (oEvent) {
       var oEventSource = oEvent.getSource();
       if (!this._oPopover) {
            // Fragment does not yet exist, load and then open it
            Fragment.load({
                name: "com.namespace.view.CancelPopover",
                controller: this
            }).then(function (oPopover) {
                // Persist reference to the fragment
                this._oPopover = oPopover;
                this.getView().addDependent(this._oPopover);
                this._oPopover.openBy(oEventSource);
            }.bind(this));
        } else {
            // Fragment does already exist, open it
            this._oPopover.openBy(oEventSource);
        }
   }

对于忙于不工作的人:

您正在使用

var inactiveDialog = sap.ui.getCore().byId("inactivedialog");

无法正常工作,请查看here