这是 SAPUI5 中的 ODatav2 调用。我使用 anywhereh.herokuapp.com 代理解决了 cors 的问题。 在 OData V2 中,我可以使用函数 oData_Model.Read
从 Northwind - Service 获取数据sap.ui.define([
"sap/ui/model/json/JSONModel",
"sap/ui/model/odata/v2/ODataModel",
"sap/m/MessageBox"
],
function (JSONModel, ODataModel, MessageBox) {
"use strict";
return {
//create NW-Model
create_NW_oModel: function () {
var service_Url = "https://cors-anywhere.herokuapp.com/https://services.odata.org/v2/northwind/northwind.svc/"
//var oData_Model = new sap.ui.model.odata.v2.ODataModel(service_Url, true);
console.log("oData_Model_NW:");
//console.log(oData_Model);
/*
//console.log(oData);
oData_Model.read("/Customers('ALFKI')", {
success: function (oData) {
console.log("oData_IN_NW");
console.log(oData);
var JSON_oModel = new sap.ui.model.json.JSONModel();
JSON_oModel.setData(oData);
console.log("test");
sap.ui.getCore().setModel(JSON_oModel, "NW_oModel");
},
error: function () {
alert("Konnte ODATA-Service nicht laden!");
}
});
},
现在我想使用 OData V4 从 Northwind 服务获取数据。没有办法用 OData V2 函数获取 V4 中的数据,所以我用 callFunction 厌倦了它。但它不起作用。 我只想在控制台上输出 Northwind 数据。
create_NW_oModel: function () {
var oModel = new sap.ui.model.odata.v4.ODataModel({
serviceUrl: "https://services.odata.org/V4/Northwind/Northwind.svc/",
synchronizationMode: "None",
defaultBindingMode: "TwoWay"
});
oModel.callFunction("Customers('ALFKI')", {
method: "GET",
success: function (oData, response) {
// success callback function
console.log(oData); // Log the returned data to the console
},
error: function (oError) {
// error callback function
console.log(oError); // Log the error to the console
}
});
},
我在谷歌等搜索并尝试了很多其他功能。