Technology Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
kiran_israni3
Participant
2,398
Hello Folks

Another blog of aggregation binding.

The following example is created in eclipse. To run the sample code in SAP WEBIDE, there will be minor changes. If your basics are clear, then surely, you will spot the change. If you face any challenge while using the sample code in SAP WEBIDE, feel free to comment, and I will help you.

  1. Create a project in Eclipse. My project structure is as shown below:




2. Sample Code in Home.View.xml
<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" controllerName="charts.Home" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Products List">
<content>
<List id="idProducts" items="{ProductModel>/results}" noDataText="Loading...">
<StandardListItem title="{ProductModel>ProductName}"/>
</List>
</content>
</Page>
</core:View>

3. Sample Code in Home.controller.js
onInit: function() {
// local proxy for cross-domain access
// create OData model from Northwind URL
var oModel = new sap.ui.model.odata.ODataModel("proxy/http/services.odata.org/Northwind/Northwind.svc", true);
oModel.read("/Products", null, null, true, fSuccess, fError);
//If data is successfully read
function fSuccess(productdata){
var oProducts = new sap.ui.model.json.JSONModel();
sap.ui.getCore().setModel(oProducts,"ProductModel");
oProducts.setData(productdata);
};
//If fails to read data
function fError(oEvent){
console.log("Error occured while reading Product Data!")
};


},

 

Note : If you are getting error "XMLHttpRequest cannot load http://services.odata.org/Northwind/Northwind.svc/$metadata. Invalid HTTP status code 501"  then use url as proxy/http/services...............else, http://services. will work.

 

Please revert for any query.

 

Thanks!!!

 

Regards

Kiran Israni

 

 
2 Comments