cancel
Showing results for 
Search instead for 
Did you mean: 

How to save the values of a ComboBox in an array?

GabrielGomezPad
Participant
0 Kudos

Hello Experts,

I am trying to fetch the values of a list and save them in a variable (array variable). For example, in the following bin:

JS Bin - Collaborative JavaScript Debugging

The expected result would be a variable

oColors = ['Blue' , 'Brown' ,'Green' , 'Black']

By Debbugging I could see the values of the binding variable, but I could not come up with the way of saving them in an array.  Thank you in advance,

Gabriel

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

oColors = $.map(this.byId("Farbe").getItems(), function (item, i) { return item.getKey(); } )

or

$.map(this.byId("Farbe").getItems(), function (item, i) { return item.getText(); } )

Answers (2)

Answers (2)

GabrielGomezPad
Participant
0 Kudos

Thank you very much. Both methods work perfectly.  I just would like to address one small doubt:

After placing the code, the array obtains a value of [0] because the list has not been populated with items yet.

I currently place the map funcion (the solution) after the filter is executed and the filter is executed after the user clicks on each IconTabFilter:

onSelectChanged: function(oEvent) {
    var key = oEvent.getParameters().key;
  

if (key === '2') {

Filter and then map function.

At this point the data is still not in the list. What would be your suggestion to place the map function in the controller? onAfterRendering (like in the jsbin) does not give me the results.

Thank you in advance,

Gabriel

former_member182372
Active Contributor
0 Kudos

once you do a filter on binding, you have to "push" (or notify) corresponding control that data is chnaged. method is:

/**

* Check whether this Binding would provide new values and in case it changed,

* inform interested parties about this.

*

* @param {boolean} bForceupdate

*

*/

JSONListBinding.prototype.checkUpdate = function(bForceupdate)

saivellanki
Active Contributor
0 Kudos

Hi Gabriel,

Makism solution should work. An alternative of the same using for loop: JS Bin - Collaborative JavaScript Debugging


Regards,

Sai Vellanki.

former_member182862
Active Contributor
0 Kudos

I think Maksim's solution is more elegant. At least for javascript, using map function to pick up the property that we want is more readable.

Thanks

-D

saivellanki
Active Contributor
0 Kudos

Dennis,

Agreed!

Regards,

Sai Vellanki.