Merging arrays with 1 being a parent element

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
bmcgonag
Posts: 40
Joined: Thu Mar 13, 2014 6:51 pm

Merging arrays with 1 being a parent element

Post by bmcgonag » Fri Mar 27, 2020 2:23 pm

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.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Merging arrays with 1 being a parent element

Post by Klaus » Fri Mar 27, 2020 2:36 pm

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

bmcgonag
Posts: 40
Joined: Thu Mar 13, 2014 6:51 pm

Re: Merging arrays with 1 being a parent element

Post by bmcgonag » Fri Mar 27, 2020 2:48 pm

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.

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Merging arrays with 1 being a parent element

Post by Klaus » Fri Mar 27, 2020 2:48 pm

You're welcome! :D

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”