Page 1 of 1

Merging arrays with 1 being a parent element

Posted: Fri Mar 27, 2020 2:23 pm
by bmcgonag
Good day all,

I have data returned from a web-service that I use JSONtoArray() to convert to an array. I can read out the elements I want, and all is good. I'll then use data from that array to call another API endpoint to request more data based on that value. I want to use a tree view to fold the 2nd sets of data under the data that was used to get it.

Essentially, I ask for Networks that are mine on an overlay VPN. Next, I use the Network ID to request a list of member machines that are on that network, their IP, status, etc. So I want the Network at the top level,a nd when I expand I want to list each Machine, IP, and Online Status.

Code: Select all

+ Network1
+ Network2
and then you'd see, upon expanding Network1, something like:

Code: Select all

- Network1
    iMac27-201    10.141.34.21    Online
    iMac27-910    10.141.34.52    Online
    Mac-Mini1     10.141.34.192  Offline
    Win10-401     10.141.34.215  Offline
    Ubuntu871     10.141.34.221  Online
+ Network2
Something like this. My thought is I need to merge the arrays, with 1 array inside the other, and I know how I would do it in Javascript, but still getting the hang of LiveCode.

Note the Call to get machine info and status will be a repeated call on a timer. The Network call will also be repeated but much less often. Not sure that matters, but it may affect any answers I suppose.

Any help or pointers is greatly appreciated.

Re: Merging arrays with 1 being a parent element

Posted: Fri Mar 27, 2020 2:36 pm
by Klaus
Hi bmcgonag,

not sure what you need exactly, but here are solutions:
1. Put both arrays into ONE other array:

Code: Select all

...
put network1 into thenewarray[1]
put network2 into thenewarray[2]
...
2. Put one array into the other array:

Code: Select all

...
put network2 into network1["network2"]
...
Is that what you mean?

Best

Klaus

Re: Merging arrays with 1 being a parent element

Posted: Fri Mar 27, 2020 2:48 pm
by bmcgonag
Hi Klaus,

And thank you, yes, I think the syntax on your second option is what I'm looking for. Sorry, just syntax is throwing me. I appreciate it.

Re: Merging arrays with 1 being a parent element

Posted: Fri Mar 27, 2020 2:48 pm
by Klaus
You're welcome! :D