What is the correct syntax for creating keys within the coldfusion structure, which is an array? Preferably in cfscript tags
To give a clear idea about what I am trying to do, here I thought it could be:
StructInnsert (account [i ], "Children [numbers child]", z); Where "baby" was considered an array and numbildren was a counter in a loop.
Obviously this does not work. It only tells me an error that the key "child [num childild]" already exists.
You say "account" structure which is called "child" which is an array. It does not make any sense if "child" is an array, then this structure can not be done if it is a structure, it can not be an array. Strains can be in an array, and strokes can contain arrays.
A straight is a map or hash, in other words, the name contains the value pair. An array is a set or a list of values. You can loop on them, or access them through their numeric index.
Let's make the account a straight, and make the child an array.
& lt; Cfset account = struct new () /> & Lt; Cfset account Child = arrenue (1) /> The account is a straight one, so you can use the structure functions on it (Structure Kexists, Structure Instructor). Account. Hair is an array, so you can use array function on it (arrayAppend, etc.). Account. Children, having an array can have a lot of value in an entry, along with complex values. So we create an account. Hair an array of strokes.
We say that in your example, z is a structure that looks like this:
You can add to this account. Children like this:
& lt; Cfset ArrayAppend (account.child, z) / & gt; Or, you can do this directly through the index:
& lt; Cfset account.child [numChildren] = z / & gt; Say now that you want to keep the account a straight one, but you want 1 key for every child in the structure, do not use an array. You can do this by using the dynamic key:
& lt; Cfset account ["child_ # numChildren #"] = z / & gt; FYI, structInnsert is usually an unnecessary task.
Comments
Post a Comment