cancel
Showing results for 
Search instead for 
Did you mean: 

retrieve bindingcontext from list and standardlistitem

Former Member
0 Kudos

Hi everyone,

I think this is a silly question but since I am a newbie and i am trying to learn sapui5 kindly guide me  .I am using a sap.m.List and sap.m.StandardlistItem as a template to the list.

Now sap.m.list has some events like select , selectionchange etc and whereas sap.m.standardlistitem has some events like tap, press etc.

Now my question is

1. To which control should i set my model to (is it list or standardlistitem)

2. In  Which event should i  get the bindingcontext ? is it inside the list events or standardlistitem events?

3. I have seen to retrieve a bindingcontext we have 2 ways

a)  oEvent.getSource().getBindingContext()

b) oEvent.getParameter("listItem").getBindingContext()

I am confused which one to use to retrieve the bindingcontext . It has become like a trial and error for me, if one doesn work i choose another one.

So kindly guide me what approach should one take to retieve the bindingcontext

Thanks &regards

Lahari

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi lahari,

1. You have to set a model to the control which has an aggregation associated with it. So in your case it should be sap.m.List

2. You can use either of the events to get the binding context (i.e you can get the bindingcontext from list events as well as standardlistitem events)


3.1 .Get BindingContext from list events

for example in select event you have to use oevent.getParameter("listItem").getBindingContext()

here is the api doc JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.m.ListBase

You can refer the example provided by sai for getting the bindingcontext from list events

3.2 Get BindingContext from StandardListItem events

For example in press event you have to use oevent.getSource().getBindingContext()

here is an example.


JS Bin - Collaborative JavaScript Debugging



Answers (3)

Answers (3)

santhu_gowdaz
Active Contributor
0 Kudos

1. To which control should i set my model to (is it list or standardlistitem)

To List- Set your model to list and bind its properties to your standardlist(Example: need to bind model to List and the records values will shown based on your standardlist)

2. In  Which event should i  get the bindingcontext ? is it inside the list events or standardlistitem events?

In list event-

ex:


  onSelectionChange : function (oEvt)

{ var oList = oEvt.getSource();

var oLabel = this.getView().byId("idFilterLabel");

var oInfoToolbar = this.getView().byId("idInfoToolbar");

// With the 'getSelectedContexts' function you can access the context paths

// of all list items that have been selected, regardless of any current

// filter on the aggregation binding. var aContexts = oList.getSelectedContexts(true);


3. I have seen to retrieve a bindingcontext we have 2 ways

a)  oEvent.getSource().getBindingContext()

b) oEvent.getParameter("listItem").getBindingContext()

This is correct- oEvent.getParameter("listItem").getBindingContext();

Because you will bind your model to list. so "listItem" will gives you the correct Binding.

saivellanki
Active Contributor
0 Kudos

Hi Lahari,

oEvent.getParameter("listItem").getBindingContext() is correct.

Check this sample for more info - JS Bin - Collaborative JavaScript Debugging

I used alerts to show model Path and data that has binded to standardListItem.

Regards,

Sai Vellanki.

Former Member
0 Kudos

1. you have to set your model to a list


var list = new sap.m.List();

var standardlistitem = new sap.m.StandardListItem({

              title : "{ProductName}"

          });

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

list.setModel(oModel);  

list.bindAggregation(“items","/ProductID" , standardlistitem);

for get the binding items;


oEvent.getSource().getBinding("items");