Mark Luffel
unread,Dec 10, 2007, 2:23:11 PM12/10/07Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to appcelerator...@googlegroups.com
I've added new functionality to the iterator widget that makes it easier to use, especially with nested datastructures.
The first change is that an iterator can now accept a JSON array to iterate over,
and can access the variables of the array with the
#{iterator_value} variable.
For example:
<app:iterator items="[2, 2, 3, 5, 7, 37, 151, 3329, 23833]">
#{iterator_value},
</app:iterator>
The old version of this would have been something like:
<app:iterator on="l:padovan_primes.load then execute" property="values">
#{value},
</app:iterator>
<app:message name="l:padovan_primes.load" args="{values: [{value:2}, {value:2}, {value:3}, {value:5}, {value:7}, {value:37}, {value:151}, {value:3329}, {value:23833}]}">
So this change removes a bit of boilerplate, but more importantly, allows us to execute a nested iterator whenever its parent iterator is executed. In the following example, the
#{fields} variable is a list that will be iterated over for each row of the tables variable.
<app:iterator on="r:nested.load then execute" property="tables">
<html:div>
#{table_name}
<html:div>
<app:iterator items='#{fields}'>
#{field_name} :: #{field_type},
</app:iterator>
</html:div>
</html:div>
</app:iterator>
<app:script on="l:app.compiled then execute">
/* server-side mock of some nested datastructure */
$MQ('r:nested.load', {
tables: [
{
table_name : 'Cats',
fields: [
{field_name: 'id', field_type: 'int'},
{field_name: 'age', field_type: 'int'},
{field_name: 'name', field_type: 'string'},
{field_name: 'favorite_milk', field_type: 'int', foreign_key: 'MilkBrands'},
{field_name: 'owner', field_type: 'int', foreign_key: 'People'}
]
},
{
table_name : 'Dogs',
fields: [
{field_name: 'id', field_type: 'int'},
{field_name: 'age', field_type: 'int'},
{field_name: 'name', field_type: 'string'},
{field_name: 'owner', field_type: 'int', foreign_key: 'people'}
]
},
{
table_name : 'People',
fields: [
{field_name: 'id', field_type: 'int'},
{field_name: 'age', field_type: 'int'},
{field_name: 'name', field_type: 'string'}
]
},
{
table_name : 'MilkBrands',
fields: [
{field_name: 'id', field_type: 'int'},
{field_name: 'name', field_type: 'string'}
]
}
]
});
</app:script>
And so on...