C/C++教程

SAPUI5 Walkthrough Step 26: Remote OData Service

本文主要是介绍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"
            }]
        }
    }
}

 

执行

 

 

执行无数据, 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的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!