繁忙的指示器在过滤值sapui5后不会停止

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

我有一个主从页面。在母版页中,有一个带有搜索栏的列表。当我搜索列表中的项目时,搜索会正常进行,但是当我搜索列表中不存在的项目时,繁忙指示器会自动显示,并且不会停止。以下是我的搜索代码:

    onInit: function () {

        this.router = sap.ui.core.UIComponent.getRouterFor(this);
        this._custTemp = this.getView().byId("listItemTemp").clone();
        this.refreshFlag = true; // Flag to get new data or not for customers

        this.totalModel = sap.ui.getCore().getModel("totalModel");
        this.getView().setModel(this.totalModel, "totalModel");

        this.oInitialLoadFinishedDeferred = jQuery.Deferred();
        var oEventBus = sap.ui.getCore().getEventBus();

        this.getView().byId("listId").attachEvent("updateFinished", function () {
            this.oInitialLoadFinishedDeferred.resolve();
            oEventBus.publish("MasterPage", "InitialLoadFinished", {
                oListItem: this.getView().byId("listId").getItems()[0]
            });
            if (!sap.ui.Device.system.phone) {
                this._getFirstItem();
            }
        }, this);

    },


    waitForInitialListLoading: function (fnToExecute) {
        jQuery.when(this.oInitialLoadFinishedDeferred).then(jQuery.proxy(fnToExecute, this));
    },

    _getFirstItem: function () {
        sap.ui.core.BusyIndicator.show();
        this.waitForInitialListLoading(function () {
            // On the empty hash select the first item
            var list = this.getView().byId("listId");
            var selectedItem = list.getItems()[0];
            if (selectedItem) {
                list.setSelectedItem(selectedItem, true);
                var data = list.getBinding("items").getContexts()[0];
                sap.ui.getCore().getModel("detailModel").setData(data.getObject());
                sap.ui.getCore().getModel("detailModel").refresh(true);

                this.router.navTo('DetailPage', {
                    QueryNo: data.EICNO
                });
                sap.ui.core.BusyIndicator.hide();
            }
        }, this);
    },

    onBeforeRendering: function () {
        this._fnGetData();
    },

    _fnGetData: function (oEvent) {

        var that = this;
        this.getView().setModel(this.totalModel, "totalModel");

        if (this.refreshFlag === true) {
            sap.ui.core.BusyIndicator.show(0);

            $.ajax({
                url: "/sap/opu/odata/sap/ZHR_V_CARE_SRV/EmpQueryInitSet('10002001')?$expand=QueryLoginToQueryList/QueryToLog",
                method: "GET",
                dataType: "json",
                success: function (data) {
                    that.getView().getModel("totalModel").setData(data.d.QueryLoginToQueryList);

                    that.refreshFlag = false;
                    sap.ui.core.BusyIndicator.hide();
                    that._getFirstItem();

                }
            });

        },

      onSearch: function (oEvent) {
        var that = this;
        var sValue = oEvent.getSource().getValue();
        if (sValue !== "") {
            var oFilter1 = new Filter("FunctionDes", sap.ui.model.FilterOperator.Contains, sValue);
            var oFilter2 = new Filter("EICNO", sap.ui.model.FilterOperator.Contains, sValue);
            var oFilter3 = new Filter("REQSTATUS", sap.ui.model.FilterOperator.Contains, sValue);

            var oFilter = new Filter({
                filters: [oFilter1, oFilter2, oFilter3],
                and: false
            });
            var oBinding = this.getView().byId("listId").getBinding("items");
            oBinding.filter([oFilter]);
        } else {
            oBinding = this.getView().byId("listId").getBinding("items");
            oBinding.filter();
        }
    },

    }

MasterPage.xml

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml"
controllerName="hmel.WeCareEmp.controller.MasterPage">
<Page title="Queries"  backgroundDesign="Solid">
    <subHeader>
        <Bar>
            <contentLeft>
                <SearchField id="searchField" placeholder="Search by Function. Eg: Salary" liveChange="onSearch" showRefreshButton="{device>/isNoTouch}"
                    enableSuggestions="true"/>
            </contentLeft>
        </Bar>
    </subHeader>
    <content>

        <List id="listId" items="{ path : 'totalModel>/results' }" noDataText="No Data" mode="SingleSelectMaster" growing="true" growingThreshold="100" growingScrollToLoad="true" selectionChange="onListSelect">
            <items>
                <ObjectListItem id="listItemTemp" type="Active" title="Date : {totalModel>SENT_ON}">
                    <attributes>
                        <ObjectAttribute title="Query No" text="{totalModel>EICNO}"/>
                        <ObjectAttribute title="Function" text="{totalModel>FunctionDes}"/>
                        <ObjectAttribute title="Query open with" text="{path: 'totalModel>OPENWITH', formatter:'hmel.WeCareEmp.controller.formatter.queryOpenWith'}"/>
                    </attributes>
                    <firstStatus>
                        <ObjectStatus text="{path:'totalModel>REQSTATUS', formatter:'hmel.WeCareEmp.controller.formatter.status'}"/>
                    </firstStatus>
                </ObjectListItem>
            </items>
        </List>
    </content>
</Page>

javascript filter sapui5 sap sap-fiori
1个回答
0
投票

查看您的代码,我怀疑问题与AJAX调用有关,并且可能是:

  • 如果未找到过滤器项,则GET返回错误-那么您应该添加一个“错误”处理程序以隐藏繁忙的控件
  • 如果未找到过滤器项,则GET返回成功-那么您对'data.d.QueryLoginToQueryList'的访问可能无法解析,并导致函数结束
© www.soinside.com 2019 - 2024. All rights reserved.