简体   繁体   English

如何在 SAPUI5 中等待 OData 服务读取操作的响应?

[英]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.里面有一个 OData 读取调用,它是基于某些条件的多个导航。 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 服务接收 OData 读取调用的响应,然后才能进行导航。 OData Model's version is 2.0 OData 模型的版本是 2.0

Can I use ' attachRequestCompleted ' in this case?在这种情况下我可以使用“ attachRequestCompleted ”吗?

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 .一种方法是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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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