问题
I need to pass a parameter in my OData.
The URL has to be like this:
http://my_gateway_system:port/sap/opu/odata/sap/ZGW_TRANSF_APPROVAL_SRV_02/ztest_nameset('RUBENS')
Below is my code:
var sServiceUrl = "http://<my_gateway_system>:<port>/sap/opu/odata/sap/ZGW_TRANSF";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "username", "password");
var oJsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/ztest_nameset('RUBENS')", null, null, true, function(oData, response) {
oJsonModel.setData(oData);
});
sap.ui.getCore().setModel(oJsonModel);
When I past the URL
http:// my_gateway_system:port/sap/opu/odata/sap/ZGW_TRANSF_APPROVAL_SRV_02/ztest_nameset('RUBENS')
in my browser, it works. But when I run my code, it's not working.
回答1:
You are using the legacy method call of ODataModel#read (with the parameters spread out). The current signature for this method is read(sPath, mParameters)
. Please check out the documentation of the method: https://openui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#read
In your concrete case, you should do something like:
oModel.read("/ztest_nameset('RUBENS')", {
filters: [/* your filters here */],
success: function(oData) {
oJsonModel.setData(oData);
}
});
Nevertheless, it is not clear what filter parameter you want to pass. In your example, you have no filter. The /ztest_nameset('RUBENS')
URI is just a plain entity set + key. It is also not clear what errors you get. I could guess that it can be a CORS issue. You seem to be making the OData calls to some other host than the one you are serving the UI5 app from.
来源:https://stackoverflow.com/questions/43520045/how-can-i-pass-filter-parameter-in-odata-read-method