cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

DataBinding: How to set BindingContext?

cmetz
Product and Topic Expert
Product and Topic Expert
0 Likes
5,717

Hey guys,

I have following JSON:

"customers": [

{

  "name": "Meyer",

  "first_name": "Hans",

  "order" : [

  {

  "article_number" :"123456",

  "description" :"Deo"

  }

  ]

},

I want to set the BindingContext for my control with this method:

setBindingContext(oContext, sName?)

How can i create object oContext?

I tried following, but its not working:

var oModel = this.getView().getModel("ModelKundenInfos");

var sPath = "/customers/0";

var context2 = {oModel : oModel, sPath : sPath};

Thanks + regards

Chris

View Entire Topic
ChandrashekharMahajan
Active Contributor
0 Likes

Hi,

Please check this example Data Binding Test Page with Master Detail and JSONModel and see the source code how bindingContext is set.

Regards,

Chandra

cmetz
Product and Topic Expert
Product and Topic Expert

Thanks for your reply Chandra.

Your are using the event to get the context object, I wanna create it manually. Any further ideas?

oTable.attachRowSelect(function(oEvent){

// get the binding context of the first selected row

var selectedRowContext = oEvent.getParameter("rowContext");

oItemsTable.setBindingContext(selectedRowContext);

});

Regards

Chris

cmetz
Product and Topic Expert
Product and Topic Expert

So I found the solution of this problem:

To create your own bindingContext you can use

new sap.ui.model.Context(the, sPath, oContext);      

So in my case:

var context3 = new sap.ui.model.Context(oModel, "/customers/0");

page.setBindingContext(context3, "ModelKundenInfos");