SAPUI5 Walkthrough Step 26: Remote OData Service

Step 26: Remote OData Service

在之前的开发中,我们都是用了本地的JSON数据来进行开发。这一步我们将调用OData接口,来提供我们所需的OData数据。

 

可以免费使用的Odata服务 https://www.odata.org/odata-services/ 

 

修改 webapp/manifest.json文件, 增加Datasource, 修改Models:invoice

{
    "_version": "1.7.0",
    "sap.app": {
        "id": "sap.ui.demo.walkthrough",
        "type": "application",
        "i18n": "i18n/i18n.properties",
        "applicationVersion": {
            "version": "1.0.0"
        },
        "title": "{{appTitle}}",
        "description": "{{appDescription}}",
        "sourceTemplate": {
            "id": "ui5template.basicSAPUI5ApplicationProject",
            "version": "1.40.12"
        },
        "dataSources": {
            "invoiceRemote": {
                "uri": "https://services.odata.org/V2/Northwind/Northwind.svc/",
                "type": "OData",
                "settings": {
                    "odataVersion": "2.0"
                }
            }
        }
    },

......
    "sap.ui5": {
......
        "models": {
            "i18n": {
                "type": "sap.ui.model.resource.ResourceModel",
                "settings": {
                    "bundleName": "sap.ui.demo.walkthrough.i18n.i18n"
                }
            },
            "invoice": {
                "dataSource": "invoiceRemote"
            }
        },
        "resources": {
            "css": [{
                "uri": "css/style.css"
            }]
        }
    }
}

 

执行

SAPUI5 Walkthrough Step 26: Remote OData Service

 

 

执行无数据, F12查看 Console,错误信息如下:

Access to XMLHttpRequest at 'https://services.odata.org/V2/Northwind/Northwind.svc/$metadata?sap-language=ZH' from origin 'http://localhost:53084' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

查看sap的建议,解决无果

https://sapui5.hana.ondemand.com/#/topic/5bb388fc289d44dca886c8fa25da466e.html

参考下述文章后(复制一个Chrome浏览器,然后在浏览器右键属性目标框中拼接 --user-data-dir="c:\ChromeDebug" --test-type --disable-web-security)后能CORS问题解决

https://blog.csdn.net/u014089637/article/details/118904009

 

执行

SAPUI5 Walkthrough Step 26: Remote OData Service

 

上一篇:模仿微信"转你妹"游戏


下一篇:SAP OData offline store在Android平台的技术实现