forEach"
m |
m (correct highlight (via JWB)) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{ZUMLReferencePageHeader}} | {{ZUMLReferencePageHeader}} | ||
+ | '''Syntax:''' | ||
forEach="${''an-EL-expr''}" | forEach="${''an-EL-expr''}" | ||
forEach="''an-value'', ${''an-EL-expr''}" | forEach="''an-value'', ${''an-EL-expr''}" | ||
Line 6: | Line 7: | ||
The forEach attribute is used to specify a collection of object such that the XML element it belongs will be evaluated repeatedly for each object of the collection. | The forEach attribute is used to specify a collection of object such that the XML element it belongs will be evaluated repeatedly for each object of the collection. | ||
− | 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, | + | 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 this attribute is not specified or empty, it will be 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 | + | Second, you can specify a list of values by separating them with commas. Then, the associated element will be evaluated repeatedly against each value in the list. |
− | For each iteration, two variables, < | + | For each iteration, two variables, <code>each</code> and <code>forEachStatus</code>, are assigned automatically to let developers control how to evaluate the associated element. |
<source lang="xml" > | <source lang="xml" > | ||
Line 35: | Line 36: | ||
If you prefer to iterate only a portion of a collection, you could specify [[ZUML Reference/ZUML/Attributes/forEachBegin|forEachBegin]] and/or [[ZUML Reference/ZUML/Attributes/forEachEnd|forEachEnd]]. | If you prefer to iterate only a portion of a collection, you could specify [[ZUML Reference/ZUML/Attributes/forEachBegin|forEachBegin]] and/or [[ZUML Reference/ZUML/Attributes/forEachEnd|forEachEnd]]. | ||
+ | Fore more examples, please refer to [[ZK Developer's Reference/UI Composing/ZUML/Iterative Evaluation|ZK Developer's Reference: Iterative Evaluation]]. | ||
=Version History= | =Version History= | ||
Latest revision as of 13:27, 19 January 2022
Syntax:
forEach="${an-EL-expr}" forEach="an-value, ${an-EL-expr}"
The forEach attribute is used to specify a collection of object such that the XML element it belongs will be evaluated repeatedly for each object of the collection.
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 this attribute is not specified or empty, it will be 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 commas. 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>
When ZK Loader iterates through items of the give collection, it will update two implicit objects: each and forEachStatus. The each variable represents the item being iterated, while forEachStatus is an instance of ForEachStatus, from which you could retrieve the index and the previous forEach, if any.
If you prefer to iterate only a portion of a collection, you could specify forEachBegin and/or forEachEnd.
Fore more examples, please refer to ZK Developer's Reference: Iterative Evaluation.
Version History
Version | Date | Content |
---|---|---|