on 2018 Jun 11 6:26 PM
I have a simple requirement to get OData from the backend to populate the sap.m.select on my XML view. It works if I use a hard code json array in the app. or if I use a JS view but not with an XML view.
In my controller.js I have:
var sServiceUrl = "/sap/opu/odata/sap/ZRE_FACILITY_SRV/";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
OData.request
({
requestUri: "/sap/opu/odata/sap/ZRE_FACILITY_SRV/BusEntitySet",
method: "GET",
headers:
{
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/atom+xml",
"dataType" : "json",
"DataServiceVersion": "2.0"
}
},
function (oData, response) {
var oModel1 = new sap.ui.model.json.JSONModel();
oModel1.setSizeLimit(oData.results.length);
oModel1.setData(oData.results);
var oSelect = this.getView().byId("SelectID");
oSelect.setModel(oModel1, "appData1");
//oModel1.setProperty("/modelData", oData.results);
//var oSelect = this.getView().byId("SelectID");
//var oTemplate = new sap.ui.core.Item({key: "{Swenr}", text: "{Xwetext}" });
//oSelect.setModel(oModel1);
//oSelect.bindAggregation("items", "/modelData", oTemplate);
},
function (err) {alert("Error in getting Data");
} );
<Label text="Business entity" />
<Select id="SelectID" items="{ path: 'appData1>/BusEntitySet'}">
<core:Item key="{appData1>Swenr}" text="{appData1>Xwetext}" />
</Select>
Hi,
If you are using SAPUI5 and calling an odata service, you can use all the methos of the model.
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
The ODataModel, has a own method for reading, (Also, I strongly recommend you to use OData.v2), an example of a read request would be :
var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, true);
oModel.read("/EntitySet",{
success : function(oData){
alert("Success");<br> //...
},
error : function(oEvent){
//....
}
});
Try this 🙂
Hope it helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
this seems to be very much old kind of approach on accessing oData. Why not use manifest.json for instantiating oData models...and you can perform the binding to xml view
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
71 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.