forEach

From Documentation
Revision as of 02:12, 8 July 2010 by Maya001122 (talk | contribs) (Created page with '== The forEach Attribute == forEach="${''an-EL-expr''}" forEach="''an-value'', ${''an-EL-expr''}" There are two formats. First, you specify a value without comma. The value is…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The forEach Attribute

forEach="${an-EL-expr}"
forEach="an-value, ${an-EL-expr}"

There are two formats. First, you specify a value without comma. The value is usually a collection of objects, such that the associated element will be evaluated repeatedly against each object in the collection. If not specified or empty, this attribute is ignored. If non-collection object is specified, it is evaluated only once as if a single-element collection is specified.

Second, you can specify a list of values by separating them with comma. Then, the associated element will be evaluated repeatedly against each value in the list.

For each iteration, two variables, each and forEachStatus, are assigned automatically to let developers control how to evaluate the associated element.

<hbox>
	<zscript>
		classes = new String[] {"College", "Graduate"};
		grades = new Object[] {
			new String[] {"Best", "Better"}, new String[] {"A++", "A+", "A"}
		};
	</zscript>
	<listbox width="200px" forEach="${classes}">
		<listhead>
			<listheader label="${each}" />
		</listhead>
		<listitem label="${forEachStatus.previous.each}: ${each}"
			forEach="${grades[forEachStatus.index]}" />
	</listbox>
</hbox>