cfassociate


<cfassociate>

We have just discussed how to pass variables from the parent tag to the child tag. Now we have to reverse our track and discuss a way to pass child data back to parent data.

We will accomplish this task by using a ColdFusion tag called <cfassociate>. This tag grabs all attributes passed to a child tag and organizes them as structures. In our previous example, one of the declared child tags was as follows:

 <cf_menuitem text="ColdFusion"              url="productinfo.cfm?prod_ID=4"> 

If we converted the attributes of this child tag into a structure, they might be represented in this manner:

 Menu Item #1 text="ColdFusion" url="productinfo.cfm?prod_ID=4" 

If we represented the next two child tags' attributes in the same manner, we would have this:

 menu Item #2 text="JRun" url="productinfo.cfm?prod_ID=5" 

and this:

 Menu Item #3 text="Flash" url="productinfo.cfm?prod_ID=8" 

From what you know about structures and arrays, you should be able to see immediately that when you organize data in this manner, the data can be stored as an array of structures.

Lists, arrays, and structures are discussed in Chapters 13, 14, and 15, respectively.


That is exactly what <cfassociate> doesconverts every child tag's attribute set into a structure, which is then placed into an array. The syntax for the tag is:

 <cfassociate basetag="cf_menu"              datacollection="MenuItemData"> 

The first attribute, basetag, declares the parent tag to which you will be passing all the child tag data. The datacollection attribute is what you use to name the array of structures that holds the child tag data.

NOTE

If you do not explicitly name the array of structures using the datacollection attribute, ColdFusion refers to it by default as AssocAttribs.


Once all the data is passed back to the parent tag, the variable is referred to as part of the ThisTag scope. In our example, we would refer to the array of structures in the parent tag as ThisTag.MenuItemData. You would use your knowledge of arrays and structures to access the data being held within this variable.

NOTE

The array of structures is passed back to the end mode of the parent tag set.




Macromedia ColdFusion MX 7 Certified Developer Study Guide
Macromedia ColdFusion MX 7 Certified Developer Study Guide
ISBN: 0321330110
EAN: 2147483647
Year: 2004
Pages: 389
Authors: Ben Forta

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net