0

I have an error in the following code and I can't find why...

Using UiApp I define a couple of ListBox like this in a for loop

   var critGlist = app.createListBox().setName('critGlist'+n).setId('critGlist'+n).addChangeHandler(refreshGHandler).addChangeHandler(cHandlerG).setTag(listItem[n]);

I added a TAG to be able to retrieve a value in the handler function because when I add items to this list I do it like this :

   for(var c=0;c<listItem[n].length;++c){
      critGlist.addItem(listItem[n][c],c);// the returned value is c, the value shown is listItem[n][c] 
    }

Then in my handler function I retrieve the value c that is the index of an element of the array listItem[n]

Since I stored a stringified value of this array as a tag I have to retrieve the tag first and then using the index I get the desired value...

That's where it becomes problematic !

I tried the 3 following codes :

    var idx = Number(e.parameter['critGlist'+c]);// this works and I get the index

    var item = e.parameter.critGlist0_tag.split(',')[idx];// this also works for a fixed index (0 here) but I need to use it in a for loop so I tried the code below

    var item = e.parameter['critGlist'+c]_tag.split(',')[idx];// this generates an syntax error 
// error message :"Signe ; manquant avant l'instruction. (ligne 129, fichier "calculatrice Global")"
// which means : missing ; before statement (line 129...

Am I missing something obvious ? How should I write it differently ?

Obviously it is the underscore that is not accepted... but how could I not use it ?

Well, I have a few other possibilities to get the result I want (using a hidden widget for example or some other temporary storage of even let the listBox return the value instead of the index) but still I'd like to know why this syntax is wrong ...

I'm not asking for a different code (as mentioned before there are a lot of other ways to go) , just some explanation about what is wrong in this code and this #!##å»ÛÁØ underscore ;)

5
  • Its not valid javascript Commented Dec 23, 2013 at 0:06
  • But I cant get to it right now. Ill help you on this later :) Commented Dec 23, 2013 at 0:07
  • Whats _tag for and have you tried placing it as a string added after c inside the [] Commented Dec 23, 2013 at 0:15
  • Thanks, you should have made it an answer, you were first ;-) Commented Dec 23, 2013 at 7:26
  • no problem, good to have helped :) Commented Dec 23, 2013 at 12:36

1 Answer 1

1

You will need to put the whole property within the brackets as below

var item = e.parameter['critGlist'+c+'_tag'].split(',')[idx];// this generates an syntax error 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.