1

I am trying to use the value from a drop down list to reference an array which I am using to load some data via an API in the backend. So the drop down would return the variable name but then I need to send the associated array to the function. I tried (...selected_basket) syntax but that send the name not the array to the function.

    var REITS = ['DIR-UN.TO', 'HR-UN.TO'];
    var Airlines = ['AC.TO', 'IAG.LSE', 'RYA.LSE', 'AAL', 'UAL'];
    var Insurance = ['CB.US', 'AIG.US', 'CS.PA', 'ALV.XETRA', 'PNGAY.US'];
    var Technology = ['MSFT', 'AMZN', 'NOW', 'CRM'];

    export function dropdown1_change(event) {
        selected_basket = $w("#dropdown1").value;
        load_table(selected_basket);
    }

Any help would be appreciated.

Justin
  • 297
  • 1
  • 2
  • 10

1 Answers1

1

You could create a lookup object to contain those arrays:

var REITS = ['DIR-UN.TO', 'HR-UN.TO'];
var Airlines = ['AC.TO', 'IAG.LSE', 'RYA.LSE', 'AAL', 'UAL'];
var Insurance = ['CB.US', 'AIG.US', 'CS.PA', 'ALV.XETRA', 'PNGAY.US'];
var Technology = ['MSFT', 'AMZN', 'NOW', 'CRM'];
var Lookup = {REITS, Airlines, Insurance, Technology};

export function dropdown1_change(event) {
    selected_basket = Lookup[$w("#dropdown1").value];
    load_table(selected_basket);
}
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
  • 2
    Of course, you should probably define the data as `data = { airlines: [...], ... }` in the first place. – deceze Jun 08 '20 at 08:04
  • @deceze Yeah, and use `const` instead of `var`, and respect naming conventions for variables and method names, ... I thought it better to not muddy the waters. – Robby Cornelissen Jun 08 '20 at 08:05