获取SAPUI5 v2 ODataModel的服务元数据? [英] Getting service metadata of SAPUI5 v2 ODataModel?

查看:114
本文介绍了获取SAPUI5 v2 ODataModel的服务元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试获取sapui5 v2 odata模型的服务元数据. 代码:

I try to get the service metadata of a sapui5 v2 odata model. Code:

var oModel = new sap.ui.model.odata.v2.ODataModel(someServiceURL);
var oMetadata = oModel.getServiceMetadata();

这应该根据此页面工作: https://openui5beta.hana.ondemand.com/docs/guide/6c47b2b39db9404582994070ec3d57a2.html

This should work according to this page: https://openui5beta.hana.ondemand.com/docs/guide/6c47b2b39db9404582994070ec3d57a2.html

无论如何,我为oMetadata获得了"undefined". 如果我将代码更改为:

Anyhow I got "undefined" for oMetadata. If I change code to:

var oModel = new sap.ui.model.odata.v2.ODataModel({
        loadMetadataAsync : false,
        serviceUrl : someServiceURL
});

仍然oMetadata === undefined

根据SDK文档元数据应同步加载:

According to SDK documentation metadata should be loaded in sync:

返回元数据对象.请注意,将模型与 bLoadMetadataAsync = true,则此函数可能返回未定义 因为元数据尚未加载.在这种情况下,请附加到 当元数据为 可用,然后调用此函数.

Return the metadata object. Please note that when using the model with bLoadMetadataAsync = true then this function might return undefined because the metadata has not been loaded yet. In this case attach to the metadataLoaded event to get notified when the metadata is available and then call this function.

我的代码有什么问题?

我正在使用(1.28.11):

I am using (1.28.11):

<script src="https://sapui5.netweaver.ondemand.com/resources/sap-ui-core.js"    ...

我开始调试UI5代码并检测到以下行: this.bLoadMetadataAsync = true;

I started debugging the UI5 code and detected following line: this.bLoadMetadataAsync = true;

我开始调试SAPUI5代码并检测到以下行(似乎每次都被调用):

I started debugging of SAPUI5 code and detected following line (seems to be called each time):

this.bLoadMetadataAsync = true;

这是一个错误吗?还是我的代码有问题?

Is it a bug? Or is something wrong with my code?

推荐答案

解决方案: 在实际的应用程序环境中,以下内容对我有用.我猜它没有被解开是因为没有实际的数据请求:

Solution: The following worked for me in an actual application environment. I guess it not being fired in my fiddle was due to no actual data request being made:

var oModel = new sap.ui.model.odata.v2.ODataModel(<ServiceURL>);

oModel.attachMetadataLoaded(null, function(){
   var oMetadata = oModel.getServiceMetadata();
   console.log(oMetadata);
},null);

提供解决方案的方法:

好吧,所以我开始尝试一下,发现了以下内容:

Ok so I started playing around with this a bit and found the following:

  • .getServiceMetadata()sap.ui.model.odata.ODataModel正常工作.
  • 使用sap.ui.model.odata.v2.ODataModel通过网络发送了元数据请求,但以某种方式.getServiceMetadata()返回了undefined.
  • 我尝试了sap.ui.model.odata.v2.ODataModel.attachMetadataLoaded(),但该事件从未触发过. (这仅适用于我使用的jsbin)
  • .getServiceMetadata() worked fine with sap.ui.model.odata.ODataModel.
  • with the sap.ui.model.odata.v2.ODataModel the request for the metadata was sent through the network but somehow .getServiceMetadata() returned undefined.
  • I tried to sap.ui.model.odata.v2.ODataModel.attachMetadataLoaded() but the event was never fired. (This only applied in the jsbin I used)

我将用我所做的任何进一步的发现来对此进行编辑.如果您要在我的发现/测试中包含任何内容,请告诉我.

I will edit this with any further findings I make. If you have anything that should be included in my findings/testing just tell me.

bLoadMetadataAsync是可以在sap.ui.model.odata.ODataModel上设置的参数.该参数不再在sap.ui.model.odata.v2.ODataModel的API中.我认为异步加载已被选择为默认设置.

The bLoadMetadataAsync is a parameter you can set on the sap.ui.model.odata.ODataModel. The parameter is not in the API for sap.ui.model.odata.v2.ODataModel anymore. I assume that the async loading has been choosen as default.

@ user3783327在此处报告了一个错误: https://github.com/SAP/openui5/issues/564

@user3783327 Reported a bug here: https://github.com/SAP/openui5/issues/564

这篇关于获取SAPUI5 v2 ODataModel的服务元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆