在SAPUI5中加载OData时失败 [英] Fail when load OData in SAPUI5
问题描述
我已经在manifest.json中配置了用于从SAP UI5访问我的OData服务的信息
I have configured the information for accessing my OData Service from SAP UI5 in the manifest.json
{
"sap.app": { ...
},
"dataSources": {
"Test": {
"uri": "/sap/opu/odata/sap/ZHCM_SRV/",
"type": "OData",
"settings": {
"odataVersion": "2.0",
"localUri": "localService/metadata.xml"
}
}
} ...
"sap.ui5": {
"rootView": {
"viewName": "test.view.App",
"type": "XML",
"id": "app"
}, ...
"models": {
"i18n": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "test.i18n.i18n"
}
},
"Test": {
"type": "sap.ui.model.odata.v2.ODataModel",
"settings": {
"defaultOperationMode": "Server",
"defaultBindingMode": "TwoWay",
"defaultCountMode": "None"
},
"dataSource": "Test"
}
},
"routing": { ...
}
在我的Component.js中,我有:
In my Component.js I have:
init: function() {
UIComponent.prototype.init.apply(this, arguments);
this.getRouter().initialize();
this.setModel(models.createDeviceModel(), "device");
// I get the Url from configuration in Manifest.json
var sServiceUrl = this.getMetadata().getManifestEntry("sap.app").dataSources["Test"].uri;
// I create the OData
var sabModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl);
// Load the MetaData.
sabModel.getServiceMetadata();
// Binding to the Model.
this.setModel(sabModel, "Sabbatical");
当我检查oModel时,可以看到我实例化了Model,但是它是空的,没有数据...您有这种行为吗?有任何建议吗?
when I am checking the oModel I can see I have instantiated the Model but it is empty, no data... Have you had this behavior? Any suggestion???
非常感谢!! CBR
Thanks a lot!! CBR
推荐答案
到目前为止,您所做的是:建立与模型的连接.
What you have done so far is: set up a connection to the model.
如果您想用数据填充它,可以通过将模型绑定到UI元素来完成,例如表,或通过编程方式读取数据: sap.ui.model.Model getProperty().
If you want to fill it with data you can do so by either binding the model to a UI element, e.g. a table, or by reading the data programmatically: sap.ui.model.Model getProperty().
您愿意的话
var yourVariable = sabModel.getProperty('path/to/your/property');
这篇关于在SAPUI5中加载OData时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!