ArrayCollection loop through for matching items

Posted by charlie on Stack Overflow See other posts from Stack Overflow or by charlie
Published on 2010-06-08T15:30:10Z Indexed on 2010/06/08 15:32 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

Hi

I hope someone can help me.....

i am trying to build a dynamic form for a questionnaire module. Building on some previous posts I am using the process similar to that in question "http://stackoverflow.com/questions/629021/how-to-generate-a-formmxform-dynamically-in-flex" i have managed to prove out the fact of extending the XML to include a calendar, combobox etc.

my problem is that now need to get the data from an ArrayCollection rather than from an xml file. I am looking to loop through the AC and where type = "text" render a textinput field, where a type ="calendar" render a Calendar etc etc.

my code so far just looking at a textinput field (and sorry for all the comments included ;) is:-

[Bindable] public var AC:ArrayCollection = new ArrayCollection( [ {type:'text', direction:'horizontal', tooltip:'test tooltip', label:'my textbox label', id:'1'}, {type:'text', direction:'horizontal', tooltip:'another tooltip', label:'another label', id:'2'} ]);

private function init():void

{
var form:Form = new Form();

          for each(var elements:XML in AC)

   {  
                          switch( [email protected]()) 
                            { 
                                  case "text": 

                   var fi:FormItem = new FormItem(); 
                       //   fi.toolTip = elements.tooltip.toString();
                                            //   fi.required = getglobalprofile.required.toString();
                                            //   fi.direction = getglobalprofileb[i].@direction;

                      var li:Label = new Label();
                                          //  li.text = getglobalprofileb[i].@label;
                                          // li.width = 100;

                      var ti:TextInput = new TextInput(); 
                                             ti.text = "test"; 
                                      ti.width = 200;

                       form.addChild(fi);
                       fi.addChild(li);
                       fi.addChild(ti);

             //         break; 
                            }
             }    

                    this.addChild( form); 
           }   

]]>

 <mx:Form  id="form" name="form">

 </mx:Form>

if you are interested in the working xml version (rendering only) let me know and i will post this as well

© Stack Overflow or respective owner

Related posts about Xml

Related posts about flex