1 Reply Latest reply on Aug 16, 2007 5:11 PM by Swizzir

    Data model binding with a "for in" loop

    Swizzir
      I've got a data model representing form items. An example data model element and form item looks like this:
      <data_model>
      <item_1>{item1.text}</item_1>
      </data_model>

      <mx:DateField id="item1" text="{data_model.item1}"/>

      I get data back from a database as an associative array and convert it to an ArrayCollection like so:

      formData = new ArrayCollection(ArrayUtil.toArray(re.result));

      Now, if do this:

      data_model.item_1 = formData['item_1'];

      the text of form element item1 will be updated as I would expect via the binding between the two. If I iterate through the array as such:

      for (var key:String in formData) {
      data_model.key = formData[key];
      }

      the model is updated but the form element text field is not. I'd love the convenience of iterating through the array as opposed to having to type out all the model elements by hand. Ideas?