
96
DEVELOPING
COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Las
t
upda
te
d 8/5/2010
Creating and using structures
The sample code in the following discussions uses a structure called
employee,
which is used to add new employees to
a corporate information system.
Creating structures
In ColdFusion, you can create structures explicitly by using a function, and then populate the structure using
assignment statements or functions, or you can create the structure implicitly by using an assignment statement.
Creating structures using functions
You can create structures by assigning a variable name to the structure with the
StructNew
function as follows:
<cfset structName = StructNew()>
For example, to create a structure named departments, use the following syntax:
<cfset departments = StructNew()>
This statement creates an empty structure to which you can add data.
Creating structures implicitly
You can create an empty structure implicitly, as in the following example:
<cfset myStruct = {}>
<cfoutput>
Value of the first key<br>
#mystruct.key1#<br>
#mystruct["key1"]#<br>
#mystruct[key1Var]#<br>
<br>
Output the value of the key1 (string) entry using the following
notation:
•
object.property notation
•
associative array notation with a constant
•
associative array notation with a variable
<br>
Value of the second entry in the key2 array<br>
#myStruct.key2[2]#<br>
#myStruct["key2"][2]#<br>
#myStruct[key2Var][2]#<br>
#myStruct[key2Var][var2]#<br>
<br>
Output the value of the second entry in the key2 array using the
following notation:
•
object.property notation
•
associative array notation with a constant
•
associative array notation with a variable
•
associative array notation with variables for both the array and the
array index
Value of the struct2key2 entry in the key3
structure<br>
#myStruct.key3.struct2key2#<br>
#myStruct["key3"]["struct2key2"]#<br>
#myStruct[key3Var]["struct2key2"]#<br>
#myStruct.key3["struct2key2"]#<br>
#myStruct["key3"].struct2key2#<br>
<br>
Output the value of second entry in the key3 embedded structure
using the following notation:
•
object.property notation
•
associative array notation with two constants
•
associative array notation with a variable and a constant
•
object.property notation followed by associative array notation
•
associative array notation followed by object.property notation
Code
Description
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...