Hi Pathy, I made it working example, see the code below or find the attached files. Let me know, if something is not clear...
##contactListSample.mxml## <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" verticalGap="0" horizontalGap="0" creationComplete="buildCountryMap(contactListData.contact)"> <mx:Script> <![CDATA[ var countryMap : Object; var countryList : Array; function buildCountryMap(contactList : Array) : Void { countryMap = new Object(); countryList = new Array(); for (var i = 0; i < contactList.length; i++) { var country : String = contactList[i].country; var countryContacts : Array = countryMap[country]; if (countryContacts == null) { countryContacts = new Array(); countryMap[country] = countryContacts; countryList.push(country); } countryContacts.push(contactList[i]); } country_cb.selectedIndex = 0; } ]]> </mx:Script> <mx:Model id="contactListData" source="contactList.xml"/> <mx:VBox> <mx:Label text="TestPage" styleName="appTitle" /> <mx:HBox horizontalGap="2" height="100%" width="100%"> <mx:Canvas width="700" height="300"> <mx:Panel title="Details" id="main" height="300" width="700"> <mx:Form id="details" marginLeft="30" defaultButton="clearButton" visible="{details.height>0}" width="670" height="200"> <mx:FormItem label="Country"> <mx:ComboBox id="country_cb" width="200" labelField="country" dataProvider="{countryList}" selectedIndex="0" /> </mx:FormItem> <mx:Spacer height="25"></mx:Spacer> <mx:FormItem label="Contact Name"> <mx:ComboBox labelField="contactname" width="200" dataProvider="{countryMap[country_cb.selectedItem]}" /> </mx:FormItem> </mx:Form> </mx:Panel> </mx:Canvas> </mx:HBox> <mx:HBox horizontalGap="4" height="100%" width="100%"> <mx:Panel title="Data Grid" id="mainWin" height="100%" width="100%"> <mx:DataGrid id="content" height="100%" width="100%" dataProvider="{countryMap[country_cb.selectedItem]}" > <mx:columns> <mx:Array> <mx:DataGridColumn headerText="Country" columnName="country" /> <mx:DataGridColumn headerText="Contact Name" columnName="contactname" /> </mx:Array> </mx:columns> </mx:DataGrid> </mx:Panel> </mx:HBox> </mx:VBox> </mx:Application> ##contactList.xml## <?xml version="1.0" encoding="UTF-8"?> <contactlist> <contact id="1"> <country>Argentina</country> <contactname>Robert</contactname> </contact> <contact id="2"> <country>Argentina</country> <contactname>Alex</contactname> </contact> <contact id="3"> <country>Bolivia</country> <contactname>Alex</contactname> </contact> <contact id="4"> <country>Argentina</country> <contactname>Rose</contactname> </contact> <contact id="5"> <country>Argentina</country> <contactname>Robert</contactname> </contact> <contact id="6"> <country>Korea</country> <contactname>Rose</contactname> </contact> </contactlist> I hope that's what you were looking for... -abdul -----Original Message----- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 19, 2005 8:03 PM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] How to load the XML data in to mxml components w ith Sorting ...... Hi matt, Thank you very much for immediate reply. i applied that code. but i think i did some mistakes. please correct that how should i call thaty functions <mx:Script source="testObject.as"/> 1st Combo <mx:ComboBox labelField="contryN" width="200" /> 2nd Combo <mx:ComboBox labelField="Cname" width="200" dataProvider="countryMap[countryCombo.selectedItem]" /> please explain me how do i pass cantactList. Thanks & Regards pathy On 4/16/05, Matt Chotin <[EMAIL PROTECTED]> wrote: > > > I think you're going to need two data structures to help you out. The first > one can be a Map (represented in AS by an object) of countries and the > contacts that are in them. The second is an Array of the countries > themselves. > > > > Var countryMap : Object; > > Var countryList : Array; > > > > Function buildCountryMap(contactList : Array) : Void > > { > > countryMap = new Object(); > > countryList = new Array(); > > for (var i = 0; I < contactList.length; i++) > > { > > var country : String = contactList[i].country; > > var countryContacts : Array = countryMap[country]; > > if (countryContacts == null) > > { > > countryContacts = new Array(); > > countryMap[country] = countryContacts; > > countryList.push(country); > > } > > countryContacts.push(contactList[i]); > > } > > } > > > > You simply call buildCountryMap passing in your contactList and then use the > countryList for your first ComboBox and > countryMap[countryCombo.selectedItem] as the dataProvider for your second > ComboBox. > > > > That should get you started I think. > > > > Matt > ________________________________ > > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] > Sent: Friday, April 15, 2005 11:19 AM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] How to load the XML data in to mxml components with > Sorting ...... > > > > > > Hi all, > > I have an xml file in this way. > > ******** details.xml ******** > > <?xml version="1.0" encoding="UTF-8"?> > <contactlist> > <contact id="1"> > <country>Argentina</country> > <contactname>Robert</contactname> > </contact> > <contact id="2"> > <country>Argentina</country> > <contactname>Alex</contactname> > </contact> > <contact id="3"> > <country>Bolivia</country> > <contactname>Alex</contactname> > </contact> > <contact id="4"> > <country>Argentina</country> > <contactname>Rose</contactname> > </contact> > <contact id="5"> > <country>Argentina</country> > <contactname>Robert</contactname> > </contact> > <contact id="6"> > <country>Korea</country> > <contactname>Rose</contactname> > </contact> > </contactlist> > > ____________________________________________ > > > Flex Application File > > ************ Main.mxml ******************* > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application > xmlns:mx="http://www.macromedia.com/2003/mxml" > verticalGap="0" horizontalGap="0"> > > <mx:Model id="myData" source="details.xml"/> > > <mx:VBox> > <mx:Label text="TestPage" styleName="appTitle" /> > <mx:HBox horizontalGap="2" height="100%" width="100%"> > <mx:Canvas width="700" height="300"> > <mx:Panel title="Details" id="main" height="300" width="700"> > <mx:Form id="details" marginLeft="30" defaultButton="clearButton" > visible="{details.height>0}" width="670" height="200"> > <mx:FormItem label="Country"> > <mx:ComboBox labelField="contryN" width="200" /> > </mx:FormItem> > <mx:Spacer height="25"></mx:Spacer> > <mx:FormItem label="Contact Name"> > <mx:ComboBox labelField="Cname" width="200" /> > </mx:FormItem> > </mx:Form> > </mx:Panel> > </mx:Canvas> > </mx:HBox> > <mx:HBox horizontalGap="4" height="100%" width="100%"> > <mx:Panel title="Data Grid" id="mainWin" height="100%" width="100%"> > <mx:DataGrid id="content" height="100%" width="100%" > > <mx:columns> > <mx:Array> > <mx:DataGridColumn headerText="Country" > columnName="country" /> > <mx:DataGridColumn headerText="Contact Name" > columnName="cname" /> > </mx:Array> > </mx:columns> > </mx:DataGrid> > </mx:Panel> > </mx:HBox> > </mx:VBox> > </mx:Application> > > __________________________________ > > In flex I have two combo components. In the first combo box I want to > load all the country names in it. when i select one country i need to > load all contactnames for that perticular contry in 2nd combo. > > When I change the country in the first combo box I want the contact > name also to be changed. It's something like data binding. > > The selected country's name and contactnames should come in to > the datagrid component also. Can anybody please help me out. I am new > to > the Flex. > > > > Thanks in advance........... > Will be eagerly waiting for some response > > regards, > Pathy > > > > > > > > ________________________________ > Yahoo! Groups Links > > To visit your group on the web, go to: > http://groups.yahoo.com/group/flexcoders/ > > To unsubscribe from this group, send an email to: > [EMAIL PROTECTED] > > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. Yahoo! Groups Links Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
contactList.xml
Description: Binary data
index.mxml
Description: Binary data