Adobe COLDFUSION 9 Manual page 99

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
Notation
Object.property
Associative arrays
Structure
Referencing complex structures
When a structure contains another structure, you reference the data in the nested structure by extending either
object.property or associative array notation. You can even use a mixture of both notations.
For example, if structure1 has a key key1 whose value is a structure that has keys struct2key1, struct2key2, and so on,
you can use any of the following references to access the data in the first key of the embedded structure:
Structure1.key1.Struct2key1
Structure1["key1"].Struct2key1
Structure1.key1["Struct2key1"]
Structure1["key1"]["Struct2key1"]
The following example shows various ways you can reference the contents of a complex structure:
Description
You can reference a property, prop, of an object, obj, as obj.prop. This notation, also called dot notation, is
useful for simple assignments, as in this example:
depts.John="Sales"
Use this notation only when you know the property names (keys) in advance and they are strings, with no
special characters, numbers, or spaces. You cannot use the dot notation when the property, or key, is
dynamic.
If you do not know the key name in advance, or it contains spaces, numbers, or special characters, you can
use associative array notation. This notation uses structures as arrays with string indexes; for example:
depts["John"]="Sales"
depts[employeeName] = "Sales"
You can use a variable (such as employeeName) as an associative array index. Therefore, enclose any literal
key names in quotation marks.
For information on using associative array references containing variables, see
structure
references" on page 74.
Use structure notation only when you create structures and set their initial values, not when you are
accessing or updating structure data, and only on the right side of an assignment expression. This notation
has the following format:
{keyName=value[,keyName=value]...}
where the square braces ([]) and ellipses (...) indicate optional contents that can be repeated.
The following example creates a structure that uses structure notation:
<cfset name={firstName = "John", lastName = "Smythe"}>
Last updated 8/5/2010
94
"Dynamically constructing

Advertisement

Table of Contents
loading

Table of Contents