cancel
Showing results for 
Search instead for 
Did you mean: 

How to access data from multiple models

Former Member
0 Kudos

Hi

I am trying to create couple of oData models in my control.

var oModel = new sap.ui.model.json.JSONModel("http://services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json"); 

  sap.ui.getCore().setModel(oModel,"customers");

 

  var oModel1 = new sap.ui.model.json.JSONModel("http://services.odata.org/V3/Northwind/Northwind.svc/Products?$format=json"); 

  sap.ui.getCore().setModel(oModel1,"products");

I am trying to access the value of these odata models like below

var otemplate = new sap.ui.commons.TextView({text:"{customers>ContactName}"})

  oTable.addColumn(new sap.ui.table.Column({

   label: new sap.ui.commons.Label({text: "Contact Name"}),

   visible: true,

   template: otemplate  

  })); 

  var oControl = new sap.ui.commons.TextView({text:"{customers>ContactTitle}"})

  oTable.addColumn(new sap.ui.table.Column({

   label: new sap.ui.commons.Label({text: "Contact Title"}),

   visible: true,

   template: otemplate

  }));

I am unable to success, and my browser not throwing any errors.

Anyone help?

Thanks

Prasad

Accepted Solutions (0)

Answers (3)

Answers (3)

kedarT
Active Contributor
0 Kudos

Hi Durga,

Hope this example helps - JS Bin - Collaborative JavaScript Debugging

santhu_gowdaz
Active Contributor
0 Kudos

If you use JSon Model how you will get the data
(its client side model ).so use odata model and bind aggregation,

Binding oData into table(sap.m.table) in SAPUI5 | SCN

SAPUI5 Table binding with ODATA model. | SCN

OData Model and Data Binding | SCN

Refer for multimodel concept-

http://stackoverflow.com/questions/27166691/sapui5-multimodel-binding

Private_Member_15166
Active Contributor
0 Kudos

Have you binded your table??

Use like this.

oTable.bindRows("products>/Products");

Former Member
0 Kudos

Hi Dhananjay,

I tried with oTable.bindRows("customers>/Customers");

and also oTable.bindRows("customers/Customers");

but I am not getting any output.

Thanks

Prasad


Qualiture
Active Contributor
0 Kudos

When you access this 3rd party odata service, I'm sure you have disabled CORS in your browser and you don;t get any errors in your browser console?

Private_Member_15166
Active Contributor
0 Kudos

I will suggest one more thing, if you are testing it in localhost then use URL with proxy like below.

var oModel = new sap.ui.model.json.JSONModel("proxy/http/services.odata.org/V3/Northwind/Northwind.svc/Customers?$format=json");


Which browser you are using??