Skip to Content

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 28, 2015 at 11:23 PM

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

    or

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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 29, 2015 at 04:12 AM

    Hi Gabriel,

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


    Regards,

    Sai Vellanki.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 29, 2015 at 11:59 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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)