
101
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
<cfset structRef.key1="1C">
<cfset structRef.key3[2]="4C">
<cfset structRef.key4.Struct2key2="6C">
Original structure<br>
<cfdump var=#myNewStructure#><br>
Copied structure<br>
<cfdump var=#CopiedStruct#><br>
Duplicated structure<br>
<cfdump var=#DupStruct#><br>
Structure reference
<cfdump var=#structRef#><br>
<br>
Clear the original structure<br>
<cfset foo=structclear(myNewStructure)>
Original structure:<br>
<cfdump var=#myNewStructure#><br>
Copied structure<br>
<cfdump var=#CopiedStruct#><br>
Duplicated structure<br>
<cfdump var=#DupStruct#><br>
Structure reference:<br>
<cfdump var=#structRef#><br>
Deleting structure elements and structures
To delete a key and its value from a structure, use the
StructDelete
function, as follows:
StructDelete(structure_name, key [, indicateNotExisting ])
The
indicateNotExisting
argument tells the function what to do if the specified key does not exist. By default, the
function always returns True. However, if you specify True for the
indicateNotExisting
argument, the function returns
True if the key exists and False if it does not.
You can also use the
StructClear
function to delete all the data in a structure but keep the structure instance itself,
as follows:
StructClear(structure_name)
If you use
StructClear
to delete a structure that you have copied using the
StructCopy
function, the specified
structure is deleted, but the copy is unaffected.
If you use
StructClear
to delete a structure that has multiple references, the function deletes the contents of the
structure and all references point to the empty structure, as the following example shows:
<cfset myStruct.Key1="Adobe">
Structure before StructClear<br>
<cfdump var="#myStruct#">
<cfset myCopy=myStruct>
<cfset StructClear(myCopy)>
After Clear:<br>
myStruct: <cfdump var="#myStruct#"><br>
myCopy: <cfdump var="#myCopy#">
Looping through structures
You can loop through a structure to output its contents, as the following example shows:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...