简体   繁体   中英

How to await the response of an OData service's read operation in SAPUI5?

There is a OData read call inside which are multiple navigations based on certain conditions. For only one of the condition, it is required that the OData read call's response should entirely be received from the OData service and only then the navigation should occur. OData Model's version is 2.0

Can I use ' attachRequestCompleted ' in this case?

Currently what seems to be happening is that the view is being navigated and data is received after this navigation.

Please help. Many thanks!

A way is jQuery Deferred .

myMethod: function(){
    var oRouter = this.getRouter();

    jQuery.when(
        this.myRequest()
    ).then(function (sPage) {
        oRouter.navTo(sPage);
    }); 
},

myRequest: function(){
    var RequestDeferred = jQuery.Deferred();
    var oModel = this.getModel();

    oModel.read("/myEntity", {
        success: function(oResponse){
            //do something    
            RequestDeferred.resolve(oResponse.page); //Calls "then" in myMethod
        }
    });
    return RequestDeferred;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM