Heirarchical ArrayCollection Syntax

I am attempting to create a list based on heirarchical data, but I am struggling with the syntax to determine if there are children and how to reference and display them under a parent. I can do this with XML data(thanks to example from Alex Hauri), but I need to use an ArrayCollection.
    ArrayCollection:
   private var dpHierarchy:ArrayCollection = new ArrayCollection([
    {Region:"Southwest", children: [
     {Region:"Arizona", children: [
      {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
      {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
     {Region:"Central California", children: [
      {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
     {Region:"Nevada", children: [
      {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
     {Region:"Northern California", children: [
      {Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
      {Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}]}, 
     {Region:"Southern California", children: [
      {Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
      {Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}]}
    {Region:"Northwest", children: [
     {Region:"Washington", children: [
      {Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
      {Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}]}, 
     {Region:"Oregon", children: [
      {Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}]}, 
     {Region:"Idaho", children: [
      {Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}]}, 
List:
<s:List width="400" top="53" left="0" bottom="84" id="lstChartList" dataProvider="{dpHierarchy}" labelField="Region">
  <s:itemRenderer>
   <fx:Component>
    <s:ItemRenderer dataChange="update()">
      <fx:Script>
      import spark.components.List;
      private function update():void
       trace (List(owner).dataProvider[0].children);
     </fx:Script>
     <s:layout>
      <s:HorizontalLayout />
     </s:layout>
     <s:Group id="spacer" />
     <s:Label id="labelDisplay" />
    </s:ItemRenderer>
   </fx:Component>
  </s:itemRenderer>
</s:List>

Hi,
XML way is very complex.
Do this,
Create a simple Plain Class
public class DynamicHVO
                    public var id:Number;
                    public var name:String;
                    public var children:ArrayCollection = new ArrayCollection();
Where Children is again collection of objects having name field.(Children is basically for storing heirarchical elements)
Assign collection of this object as data provider to your list.

Similar Messages

  • Flex 3: syntax for populating ArrayCollection by loop

    Hi, I'm a newb. I can't find an example of how to do this. Any examples would be greatl appreciated.
    I want to chart some engineering data by populating my chart's dataprovider with an array collection (so far no problem). I want to poulate the array collection by looping through a math expression and I can't figure out the syntax for that. For example...
    [Bindable]
    private var myChartData:ArrayCollection = new ArrayCollection([
        {vertNum:100, horizNum:100}
    I want to loop through and add more points programmatically so if I loop 5 times I end up with...
    [Bindable]
    private var myChartData:ArrayCollection = new ArrayCollection([
         {vertNum:100, horizNum:100},
        {vertNum:110, horizNum:110},
        {vertNum:43, horizNum:120},
        {vertNum:88, horizNum:130},
        {vertNum:140, horizNum:140},
         // etc...
    The number of horizontal variables to plot ould be in the hundreds, so I don't want to set up a huge static array collection with expressions in each location. I'd prefer to solve the expression as a loop iterates and populate the array collection as it goes. But I haven't got a clue how to 'word' that.
    thanks!

    Here is an example of adding data points from a simple formula using a random number generator and scaling the randomness up. The process is just to create a new Object for each iteration of the loop and add the object to your ArrayCollection. You can assign as many properties to the object as you need, which can be helpful for using one ArrayCollection that is displayed in multiple charts.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="build_model()">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                private function build_model():void {
                    var obj:Object;
                    var chartAC:ArrayCollection = new ArrayCollection();
                    for (var i:uint = 0; i < 100; i++) {
                        obj = new Object();
                        obj.horizNum = 100 + 10 * i;
                        obj.vertNum = i * Math.random();
                        chartAC.addItem(obj);
                    linechart1.dataProvider = chartAC;
            ]]>
        </mx:Script>
        <mx:LineChart left="10" right="10" top="54" bottom="10" id="linechart1">
            <mx:series>
                <mx:LineSeries displayName="Series 1" yField="vertNum" xField="horizNum"/>
            </mx:series>
        </mx:LineChart>
        <mx:Button x="10" y="10" label="Build Model" click="build_model()"/>
    </mx:Application>
    Chris

  • Is there a way to call a function with in the initializer of a ArrayCollection?

        Is there a way to call a function with in the initializer of a ArrayCollection?
    It won't let me do this:
    var ac:ArrayCollection = new ArrayCollection([
                        {childName:'addTrade',index:addTradeIndex },
                        {childName:'tradeList',dealsCanvas.getChildIndex(tradeList) }

    The correct syntax is
    var ac:ArrayCollection = new ArrayCollection([
                        {childName:'addTrade',index:addTradeIndex },
                        {childName:'tradeList',index:dealsCanvas.getChildIndex(tradeList) }

  • Flex 2 Charting Multidimensional ArrayCollection

    I am trying to bind an array collection in a line chart.
    Since I can have any number of series for a given situation, I
    actuallly have an array collection with a category variable and an
    imbedded array collection. What is the syntax in the yfield
    attribute of the Line Series element to access a specific number in
    the embedded array.
    The array collection that is bound to the chart consists of
    objects that are added like so:
    siblingChartData.addItem({month:siblingXMLData[0].month
    .attribute("label").toString(), embedArray:buffer});
    Where the buffer is a separate ArrayCollection of varying
    size.
    I think it should be something along the lines of:
    yField="embedArray.getItemAt(0)"
    But this fails to work. If I just leave it at "embedArray",
    it returns the first item successfully, but there's no way to get
    any subsequent items.

    Hi,
    I had the same problem and I am also using Maven instead of
    Ant to build.
    I managed to workout that you can add the mxmlc command line
    argument, "-licenses.license charting XXXXXXXXXXX", to the
    "flex-config.xml" using the following (Note: add it outside of the
    <compiler> tag):
    <licenses>
    <license>
    <product>charting</product>
    <serial-number>XXXXXXXXXX</serial-number>
    </license>
    </licenses>
    By doing this I could continue to build my Flex code through
    maven.

  • Changing values in an ArrayCollection

    I have an ArrayCollection and i want to change property x
    where property y = wotnot
    what's the syntax for this?
    Thanks
    Mike

    "mikeLeeds" <[email protected]> wrote in
    message
    news:gjol87$gtp$[email protected]..
    > No, actually it's an arrayCollection of objects so i
    guess i need to loop
    > through the array to find the object i want ....
    Look at using a cursor.
    HTH;
    Amy

  • How to add arraycollection to the httpservice's url property??

    hi all..,
    i want to add arraycollection data to the httpservice url
    property...
    how can i add it
    can anybody explain with bit syntax??????//
    thank u...
    vijay kotha

    Try this URL :
    http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html
    and look the two last examples, I think it would solve your problem and it's a very good work.

  • Convert HierarchicalCollectionView to ArrayCollection

    I'm trying to retrieve the ArrayCollection data provided to DataGrid and AdvancedDataGrid. While gridID.dataProvider works for flat data, I'm getting coercion error when data is heirarchical. Is there a way to retrieve the original ArrayCollection data? Parsing doesn't seem to work either. TIA!

    If you have a GroupingCollection2 instance, you can still retrieve its source afterward by using something like var ac:ArrayCollection = gc.source as ArrayCollection;
    <mx:AdvancedDataGrid id="myADG"   
        <mx:dataProvider>
          <mx:GroupingCollection2 id="gc" source="{dpFlat}">
            <mx:grouping>
              <mx:Grouping>
                <mx:GroupingField name="Region"/>
                <mx:GroupingField name="Territory"/>
              </mx:Grouping>
            </mx:grouping>
          </mx:GroupingCollection2>
        </mx:dataProvider> 
        <mx:columns>
          <mx:AdvancedDataGridColumn dataField="Region"/>
          <mx:AdvancedDataGridColumn dataField="Territory"/>
          <mx:AdvancedDataGridColumn dataField="Territory_Rep"/>
          <mx:AdvancedDataGridColumn dataField="Actual"/>
          <mx:AdvancedDataGridColumn dataField="Estimate"/>
        </mx:columns>
      </mx:AdvancedDataGrid>
    In the case of this example from the livedocs, var ac:ArrayCollection = gc.source as ArrayCollection; would return a reference to dpFlat.

  • Help with ArrayCollection

    Hi,
    I need help on the syntax of how to get and set items in a 2 dimensional ArrayCollection list.  For example if I have the following:
    public var vline:ArrayCollection = new ArrayCollection([
            {time: 0, line: 10
            {time: 1, line: 0},
            {time: 2, line: 0},
            {time: 3, line: 0},
    how do I get
         line at time=1
    how to set
         line to 10 at time=2
    Hope you can help,

    You created a anonym object with a time and a line property. So you can access teh properties by:
    var obj:Object = arrCollection.getItemAt(0);
    trace(obj.time);
    trace(obj.line);
    I hope this helps!
    Flavy

  • DataProvider syntax error -why cant 2 components have the same dataProvider

    Hi,
    I am getting the following error:
    Multiple Initializers for property 'dataProvider' (note:
    'dataProvider' is the default property of
    mx.controls.TitleList').
    setup
    i have two components one that is a lineChart the other is a
    titleList. for each I have identified the dataProvider property as
    the same arrayCollection (dataPoints) so my code looks like:
    <mx:LineChart
    id="linechart"
    dataProvider="{ dataPoints }" .... other properties>
    for both components. I had this same error when i tried to
    add a legend component yesterday so it is not limited to just these
    two components. I tried instantiating a variable as a type
    dataProvider, so that it was not being instantiated twice, but no
    such primitive type was available via the auto-complete code
    function. I am not sure what else to try. Thanks,
    Jed

    Greg,
    Thanks again, I figured out the problem. In the mxml I was
    using the category axis tag without having a parent horizontal axis
    tag. So for others here is how a chart needs to be structured.
    correct syntax:
    <LineChart id="linechart1" dataProvider=" {
    myArrayCollection } ">
    <mx:horizontalAxis>
    <!--use the category axis tag to tell the chart what value
    in your array collection you want to use for the x axis-->
    <mx:CategoryAxis categoryField="x"/>
    </mx:horizontalAxis>
    <mx:series>
    <!--Use the line series within a series tag to tell the
    LineChart which y field it should use to draw the line-->
    <mx:LineSeries id="yourFirstYvalues" yField="y"/>
    </mx:series>
    </mx:LineChart>
    <mx:Legend dataProvider = "linechart1" />
    Jed

  • Filter ArrayCollection by index

    What is the syntax to reference the index in an ArrayCollection? I know if you remove  any filterFunction from an ArrayCollection it will be automatically ordered by index, but I want to explicitly refer to the index in a filterFunction:
    private function filterUsingIndexNum(item:Object):Boolean{
                           if(item.index < someValue) return true;
                           else return false;     
    // item.index is not referencing a property of the data in the ArrayCollection, I am actually trying to reference the index numder of the items in the ArrayCollection.
    Thanks.

    I just figured out the solution; actually, the correct syntax:
    private function filterUsingIndexNum(item:Object):Boolean{
                           if(theArraCollection.getItemIndex(item) < someValue) return true;
                           else return false;    

  • ArrayCollection and contains

    I have created an array of multiple objects, and want to be
    able to search in the array as I loop over rows in a datagrid to
    determine whether to add an entry to the array (if not present). At
    first I tried using indexOf, but that doesn't work if the array has
    multiple named values. I switched to adding the array to an
    arraycollection and am trying to use arraycollection.contains...
    Not having any luck, so am curious to see syntax for checking
    on the existence of a value from the array in the array collection.
    Surely it has to be easier than I am making it - here is my latest
    attempt:
    function testArray() {
    var test:Array = [{Classname:"class
    10",data:1},{Classname:"class 11",data:2}];
    var testAc:ArrayCollection = new ArrayCollection(test);
    for (var i=0;i<test.length;i++) {
    Alert.show(testAc.contains('class 10').toString());
    Hopefully someone has already done this or something similar
    Ethan

    Ethan,
    If you are going to this much trouble, you might as well
    simply capture the Classname property and push it into a seperate
    array, then go back to using indexOf.
    var nameArray:Array = new Array();
    for (var index:int=0 ; index<test.length ;index++){
    nameArray.push(test[index].Classname);
    var isItHere:int = nameArray.indexOf('Class 1');

  • ArrayCollection

    I have an arraycollection, Called myPrices. I just want to
    display the Product number from the arraycollection. I dont know
    the syntax.
    This gets me [Object.object]
    <mx:Text text="{myPrices}"/>
    If I make a datagrid and make one column be PWDL01 I get the
    record I want.
    How can I show the PWDL01 in the text?
    There is only one record in the array but a bunch of fields
    Thanks
    George

    hi George,
    you are getting object object, because it is returning an
    object.
    to get a specific item from the object within the datagrid
    mydata.selectedItem.mydatacolumn - id of my datagrid is
    mydata and the column information I want to display is
    mydataColumn.
    Now you can say this too.
    mydata.getItemAt(0).mydatacolumn - this will return the item
    in the 0 position of the data grid. remember that arrays are 0 or
    zero based, meaning they start at 0 instead of one.
    now if I wanted to get this from my array Collection I would
    call:
    myarrayCollection.getItemAt(0).mydatacolumn

  • Query elements of an ArrayCollection dynamically?

    I'm trying to filter an ArrayCollection without having to write a bunch of filter functions. What I'd like to do is have a dynamic query (or syntax).
    Something like this:
    private var query:String = new String("name");
    private function removeDuplicates(item:Object):Boolean
         var retVal:Boolean = false;
         var tempObj:Object = {};
         if (!tempObj.hasOwnProperty(item.query)) {
              tempObj[item.query] = item;
              retVal = true;
         return retVal;
    Obviously I can't just append a string variable to an Object dot syntax. Any idea how I might go about this?

    Figured it out...
    Looks like I can write it like this:
    item[query];

  • Nested ArrayCollection

    I have an ArrayCollection of 3 arrays: level0, level1, and
    level2. The level0 array item a set of x,y coordinates. The level1
    x,y coordinates are used to position ten objects relative to the
    position of the level0 object. Similarly, the level2 x,y
    coordinates are used to position ten objects relative to the
    position of a level1 object.
    I wish to designate the position of an object, say an HBox,
    with code something like:
    <mx:HBox
    x="{Number(nodeCoordinates.level0[0].x)+Number(nodeCoordinates.level1[3].x)+Number(nodeCo ordinates.level2[9].x)}"
    />
    When I compile the code I get the followign error message:
    "1119: Access of possibly undefined property level0 through a
    reference with static type mx.collections:ArrayCollection."
    I know this isn't a clean way to address the problem. At this
    early point I'm just trying to heavy-handedly get the app to do
    want I want. I'll make the code more efficient later.
    How can I reference and use the values in a nested
    ArrayCollection?
    Thank you in advance!

    "[email protected]" <[email protected]>
    wrote in message
    news:gjp8g6$ahg$[email protected]..
    > Thank you! Yes, your solution works as advertised,
    including the compiler
    > warning. :)
    >
    > I've been trying different means of using the getItemAt
    method to
    > eliminate
    > the warnings, but have come up with the proper syntax
    that recognizes
    > nested
    > arrays in an ArrayCollection. The getItemAt method
    accepts an integer
    > parameter. Does that mean I can't reference a nested
    array?
    >
    > Layout of components needs to be pretty specific. So,
    I'm not able to use
    > the
    > relative means for component layout.
    You could try something like
    x="((nodeCoordinates.getItemAt(0) as
    ArrayCollection).getItemAt(0) as
    YourDataType).x..."
    But I think what rtAlton is trying to say is that there's an
    implication
    here that you've got a "thing" at level 0 that has an x
    coordinate, and then
    you have another "thing" placed at level1 relative to the
    first thing, and
    then there's this HBox that's being positioned relative to
    the level1
    object.
    So it seems like you could do something that puts the level 0
    and level 1
    values into a variable and adds them together, then the level
    2
    ArrayCollection is pulled out as a separate variable,
    simplifying the
    references. Possibly this could be done with custom
    components that
    encapsulate each level.
    HTH;
    Amy

  • Editing a specific arraycollection element

    what is the best way to update a specific ArrayCollection
    element. The only way I've been able to do it is by using
    array-style syntax, but this does not dispatch the necessary events
    to sync a datagrid and I have to "refresh()" the ArrayCollection.
    Is there somehting I'm missing in the ArrayCollection API?
    Thaks for the help!!
    Carlos

    Try using getItemAt() instead of using the bracket syntax.
    Tracy

Maybe you are looking for

  • How to get the list of employees whose Sal on hold and who are active

    HI Experts, We are trying to extract a report,where the list of employees whose  salary was hold  and who are active in a particular month. Please advice. Regards, V Sai.

  • Can't find photo library but I can see them in photo editing apps???

    When I go to my photo app on my ipad I can see some photos but not all of them. When I tried to open one of the photo editing apps I have all of my pictures are there. Why can't I see them in the other photo app where they use to be. To my knowledge

  • Getting problem with running RWBLD60 with User parameters

    Hi All, I am trying to run a report using rwbld60 from command prompt which has input parameters I tried like this but it didnt work out rwbld60 module=reportname.rdf userid=scott/tiger@orcl destype=file desformat=pdf desname=report_out.pdf parameter

  • BRF+ Standard Integration into ICM

    Hi gurus, here: http://help.sap.com/erp2005_ehp_05/helpdata/EN/5f/b367185c4f41ccbdeb4e383d516a68/frameset.htm is a guide on how to enable BRF+ to be used as a valuation or remuneration tool in the ICM through the customizing. However, after doing all

  • Remove Dropdown box next to Star Button in Location Bar?

    I've removed the star from my location bar, but I've still got the little drop down arrow - is there a way to remove that, too? When I click on it, it just highlights blue, nothing actually happens. Maybe I have some settings wrong - and things ''sho