Javascript SAPUI5:如何在将数据推送到OData服务时显示加载对话框?

Javascript SAPUI5:如何在将数据推送到OData服务时显示加载对话框?,javascript,ajax,dialog,modal-dialog,sapui5,Javascript,Ajax,Dialog,Modal Dialog,Sapui5,我正在构建一个新的SAPUI5应用程序,而不采用任何模板方法。我正在构建的只是一个有两个字段和一个按钮的小表单。啊。。。“按钮” 按钮呢?该按钮具有以下代码: <Button text="OK" width="100%" id="__button1" press="insertIntoOData"/> 我的问题是:如何在InsertionToData结束或调用oModel.create函数之前显示对话框 当您输入insertIntoOData方法时。 在调用服务集之前 that

我正在构建一个新的SAPUI5应用程序,而不采用任何模板方法。我正在构建的只是一个有两个字段和一个按钮的小表单。啊。。。“按钮”

按钮呢?该按钮具有以下代码:

<Button text="OK" width="100%" id="__button1" press="insertIntoOData"/>

我的问题是:如何在InsertionToData结束或调用oModel.create函数之前显示对话框

当您输入insertIntoOData方法时。 在调用服务集之前

  that._dialog.setBusy(true);
将服务响应(成功或错误无所谓)设置为


当您输入insertIntoOData方法时。 在调用服务集之前

  that._dialog.setBusy(true);
将服务响应(成功或错误无所谓)设置为


您可以执行全局忙指示或组件忙指示,在
oModel之前显示。创建
并隐藏到success或error函数中:

sap.ui.core.BusyIndicator.show(0); <- Parameter is delay time.

sap.ui.core.BusyIndicator.hide();  <- hide

sap.ui.core.BusyIndicator.show(0) 您可以执行全局忙指示或组件忙指示,在
oModel之前显示。创建
并隐藏到success或error函数中:

sap.ui.core.BusyIndicator.show(0); <- Parameter is delay time.

sap.ui.core.BusyIndicator.hide();  <- hide

sap.ui.core.BusyIndicator.show(0) 我已经成功地展示了巴士指示灯。
我将InsertionToData函数重新构建为如下所示:

    insertServiceRequestIntoOData: function(evt) {

        var that = this;
        var token = null;
        var serviceUrl = "URL";

        var name_var = this.byId("tSubjectInput").getValue();
        var description_var = this.byId("tDescriptionArea").getValue();

        var oEntry = {};
        /*
         * oEntry building process omitted
         */

        this.oModel = new sap.ui.model.odata.ODataModel(serviceUrl);
        sap.ui.getCore().setModel(this.oModel);

        /*
         * This is where the magic happens:
         * 1) ajax async request to get the token and to show the busy indicator on the screen
         * 2) when it's over, make a post to the oData service with the data.
         * 3) when it's over, hide the busy indicator and go to the correct page (success or error).
         */
        $.ajax({
            url: serviceUrl + "/MyCollection";
            type: "GET",
            async: true,
            beforeSend: function(xhr) {
                sap.ui.core.BusyIndicator.show(0);
                xhr.setRequestHeader("X-CSRF-Token", "Fetch");
            },
            complete: function(xhr) {
                token = xhr.getResponseHeader("X-CSRF-Token");

                // begin of odata send
                that.oModel.create("/MyCollection", oEntry, null, function(response){
                    sap.ui.core.BusyIndicator.hide();
                    sap.ui.core.UIComponent.getRouterFor(that).navTo("insertConfirmation"); 
                    that.clearInputs();

                    },function(){
                        sap.ui.core.BusyIndicator.hide();
                        sap.ui.core.UIComponent.getRouterFor(that).navTo("insertErrorConfirmation");    
                        that.clearInputs();
                });

            }
        });
    }

我已经成功地展示了巴士指示灯。 我将InsertionToData函数重新构建为如下所示:

    insertServiceRequestIntoOData: function(evt) {

        var that = this;
        var token = null;
        var serviceUrl = "URL";

        var name_var = this.byId("tSubjectInput").getValue();
        var description_var = this.byId("tDescriptionArea").getValue();

        var oEntry = {};
        /*
         * oEntry building process omitted
         */

        this.oModel = new sap.ui.model.odata.ODataModel(serviceUrl);
        sap.ui.getCore().setModel(this.oModel);

        /*
         * This is where the magic happens:
         * 1) ajax async request to get the token and to show the busy indicator on the screen
         * 2) when it's over, make a post to the oData service with the data.
         * 3) when it's over, hide the busy indicator and go to the correct page (success or error).
         */
        $.ajax({
            url: serviceUrl + "/MyCollection";
            type: "GET",
            async: true,
            beforeSend: function(xhr) {
                sap.ui.core.BusyIndicator.show(0);
                xhr.setRequestHeader("X-CSRF-Token", "Fetch");
            },
            complete: function(xhr) {
                token = xhr.getResponseHeader("X-CSRF-Token");

                // begin of odata send
                that.oModel.create("/MyCollection", oEntry, null, function(response){
                    sap.ui.core.BusyIndicator.hide();
                    sap.ui.core.UIComponent.getRouterFor(that).navTo("insertConfirmation"); 
                    that.clearInputs();

                    },function(){
                        sap.ui.core.BusyIndicator.hide();
                        sap.ui.core.UIComponent.getRouterFor(that).navTo("insertErrorConfirmation");    
                        that.clearInputs();
                });

            }
        });
    }

如果你的请求处理得很快,那么显示一个对话框真的有意义吗?视图(和控件)具有属性
busy
,这可能更适合您的情况。Hi@Valak,使odata请求异步。默认情况下,创建请求是同步的,因此浏览器正在等待响应到达,然后继续工作。因此,一旦响应返回,它将打开弹出窗口,但下一行显示:关闭弹出窗口。因此,您将看到第二个弹出窗口。TL;DR:JS是单线程语言。使用oData.create和check的async属性。@Marc:请求非常慢,这就是为什么我要加载东西。视图的busy属性没有任何作用。@RahulBhardwaj:谢谢你的回答。我已经检查过了,因为oData.create在默认情况下是异步的。我尝试了显式显示async属性的方法。什么也没发生。所有内容都保持不变。@Valac:in-odata.create是异步的,默认为false。请你更新代码,这样我们就在同一页了。异步:必须设置true。如果您的请求处理得非常快,那么显示对话框真的有意义吗?视图(和控件)具有属性
busy
,这可能更适合您的情况。Hi@Valak,使odata请求异步。默认情况下,创建请求是同步的,因此浏览器正在等待响应到达,然后继续工作。因此,一旦响应返回,它将打开弹出窗口,但下一行显示:关闭弹出窗口。因此,您将看到第二个弹出窗口。TL;DR:JS是单线程语言。使用oData.create和check的async属性。@Marc:请求非常慢,这就是为什么我要加载东西。视图的busy属性没有任何作用。@RahulBhardwaj:谢谢你的回答。我已经检查过了,因为oData.create在默认情况下是异步的。我尝试了显式显示async属性的方法。什么也没发生。所有内容都保持不变。@Valac:in-odata.create是异步的,默认为false。请你更新代码,这样我们就在同一页了。async:必须设置为true。谢谢您的回答。我已经尝试过这种方法,但只有在odata服务发送响应后,屏幕才会变得繁忙。发生这种情况时,屏幕会“闪烁”(即,它会变忙,然后在一眨眼之间不忙),并导航回母版页。我猜这与我正在使用sapui5 fiori主细节模板有关,我的代码在细节控制器中。谢谢你的回答。我已经尝试过这种方法,但只有在odata服务发送响应后,屏幕才会变得繁忙。发生这种情况时,屏幕会“闪烁”(即,它会变忙,然后在一眨眼之间不忙),并导航回母版页。我猜这与我使用sapui5 fiori主细节模板有关,我的代码在细节控制器中。