Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to convert delimited string to an array of array names 1

Status
Not open for further replies.

bslintx2021

Technical User
Mar 19, 2021
3
US
Hi all,

Trying to figure out how to force .concat to recognize a delimited string as an array of array names.

I have an external file that contains many arrays and I want to be able to dynamically choose which arrays via tree checkboxes (named the same as the array names)

Some of the following is from a GUI library...but the issue is native JavaScript so hopefully it will be ok to read.

I am trying to figure out how to get a comma delimited string to be recognized as an array of array names so I can parse via library methods

I am not familiar with what terms so code is really the only way to let most understand what I am trying to do.

Please see in blue highlighted text in code block...this works but it's hard coded...I need it to be dynamic (variable) of array names are collected from checkboxes which creates a delimited string and pass it as a parameter in the .concat. I thought about loop and eval but was hoping not to have to go that way.

The flow is a user selects items in a tree...this info is collected in a delimited string..this string needs to be recognized as an array of arrays as seen in blue which works....then populates a grid

Definitely open to suggestions...thanks!


JavaScript:
	U_13_HTS = [
		     ["LCK","50 FF","A-000001","1909","1230000010","00000001","Smith","2019"]
                   ]

	U_215_GP = [
		     ["LCK","501 GS","A-000002","1909","1230000011","00000002","Walker","2019"],
                     ["LCK","501 GS","A-000002","1909","1230000011","00000002","Walker","2019"]
                   ]


	U_15_GP = [
		    ["RDT","542 AT","A-000003","1909","1230000013","00000002","Johnson","2019"],
                    ["RDT","542 AT","A-000004","1909","1230000014","00000002","Johnson","2020"]
                  ]


        str = "U_13_HTS,U_215_GP,U_15_GP" // hard coded for example

  	data = [].concat.apply([], [str]); 			   //str data does not work
  	data = [].concat.apply([], [eval(str)]); 		   //eval str gets last array (U_15_GP)  
 	data = [].concat.apply([], [[highlight #3465A4]U_13_HTS,U_215_GP,U_15_GP[/highlight]]); //hard coded delimited array names works   

 	myGrid_SDC.parse(data,"jsarray");
 
Hi

The brackets ( [] ) should be inside the [tt]eval()[/tt] not outside :
JavaScript:
data [teal]= [].[/teal]concat[teal].[/teal][COLOR=orange]apply[/color][teal]([],[/teal] [COLOR=orange]eval[/color][teal]([/teal][i][green]'['[/green][/i] [teal]+[/teal] str [teal]+[/teal] [i][green]']'[/green][/i][teal]))[/teal]


Feherke.
feherke.github.io
 
SMH on bracket displacement...lol...thanks that was exactly what I needed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top