New app:iterator Features

0 views
Skip to first unread message

Mark Luffel

unread,
Dec 10, 2007, 2:23:11 PM12/10/07
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...

amro

unread,
Dec 10, 2007, 4:39:36 PM12/10/07
to Appcelerator Platform SDK
great stuff
Reply all
Reply to author
Forward
0 new messages