cancel
Showing results for 
Search instead for 
Did you mean: 

Get multiple items based on drop down selected value

Former Member
0 Kudos

Hello Experts,

I have a dropdown which is bound to a list and the data is retrieved from a JSON model. Now what I want to achieve is on selection of value in the dropdown , I need to retrieve corresponding 4 values from the JSON list. Below is the code snippet for beinding :

var oListTemp = new sap.ui.core.ListItem();

        oListTemp.bindProperty("text", "projectName");

        oListTemp.bindProperty("key", "projNumber");

        oProjectsDropDown.bindItems("/projData", oListTemp);


Apart from just projectName and projNumber, I have 2 other properties whose values I need.

oProjectsDropDown.getValue(),oProjectsDropDown.getSelectedKey() - I am able to retrieve the selected value and key , but how do I retrieve other values as well depending on the corresponding selection.

Thanks & Regards,

Archana

Accepted Solutions (0)

Answers (3)

Answers (3)

qmacro
Developer Advocate
Developer Advocate
0 Kudos

You can get to the whole object within the binding context. I've put together an example for you here: http://jsbin.com/hogizu/2/edit

former_member9607
Active Participant
0 Kudos

Hi Archana,

There are many ways to do this.

On selection of item :

you can get the binding context of the selected item and use that context to read the desired property from the model.

select : function(oEvent)

{

var bindingContext = oEvent.getSource().getBindingContext();

var myProperty = oModel.getProperty("your property",bindingContext );

}

And if you are getting that selected item on some other control's event then

var bindingContext = selectedItem.getBindingContext();

var myProperty =  oModel.getProperty("your property",bindingContext );

Hope it will help you a bit.

Regards,

KK

Former Member
0 Kudos

Can someone help on this?

saivellanki
Active Contributor
0 Kudos

Hi Archana,

Instead of using bindItems method, try using bindContext method for dropdown control.

Using bindContext, you might be able to retrieve all the values that are bound to model.

I didn't worked on it, but just given a hint.

Regards,

Sai.

francesco_alborghetti
Active Participant
0 Kudos

Hi Archana,

Another way is to extend the ListItem control:

sap.ui.core.ListItem.extend("customListItem", {                                         

       metadata : {                              

            properties : {

                "property1" : "string",

                "property2" : "string",

            }

       }  

      });

Then you can bind all properties on customListItem.

Here an example:

http://jsbin.com/gufatifeqali/1/edit?html,output

Regards,

Francesco