Thanks Alex for your suggestion. I tried to extend DefaultDataDescriptor but I
found ArrayCollection method easier not sure though if it is the better way to
do. However being new to Flex, it was good to explore new things.
I wrote following function which is based on Hpet's code given at
experts-exchange. Thought to share here if anyone needs in future.
private function buildNestedArray(flatArray:ArrayCollection,
parentId:int):ArrayCollection {
/* This recursive function takes a flat Array Collection and creates a nested
Array to implement Parent/Child hierarchy*/
var i:int = 0;
var nestedArray:ArrayCollection = new ArrayCollection();
var parents:ArrayCollection = new ArrayCollection();
for (i = 0; i < flatArray.length; i++) {
if (flatArray[i]["parentId"] == parentId)
parents.addItem(flatArray[i]);
}
if (parents.length < 1)
return null;
for (i = 0; i < parents.length; i++) {
var node:Object = parents[i];
var children:ArrayCollection = buildNestedArray(flatArray,
node["itemId"]);
if (children ) {
if (children.length > 0) {
node["children"] = children;
}
}
nestedArray.addItem(parents[i]);
}
return nestedArray;
}
--- In [email protected], Alex Harui <aha...@...> wrote:
>
> There is a default implementation for simple hierarchical collections.
> Basically you will need to control what getChildren returns.
>
>
> On 4/2/10 12:08 PM, "md_ars" <mdar...@...> wrote:
>
>
>
>
>
>
> Is there any working example for its implementation?
>
> --- In [email protected] <mailto:flexcoders%40yahoogroups.com> ,
> Alex Harui <aharui@> wrote:
> >
> > OK, I think I was having trouble understanding the problem. There is an
> > IMenuDataDescriptor interface that allows you to map flat data to
> > hierarchical data.
> >
> >
> > On 4/2/10 11:04 AM, "md_ars" <mdars06@> wrote:
> >
> >
> >
> >
> >
> >
> > I used XMLList as the dataprovide and used following function as label
> > function.
> > private function get_label(item:Object):String
> > {
> > return item..stringValue[2];
> > }
> >
> > It is creating menu bar and displaying all Labels as the top level and each
> > one displaying 6 child(BLANK only Arrows) and each child displaying 2
> > child(Blank Arrow).
> >
> > --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> > <mailto:flexcoders%40yahoogroups.com> , "md_ars" <mdars06@> wrote:
> > >
> > > How do I define labelField for menu bar when using XMLList? Even though I
> > > get the label, it will return all the Menu Labels horizontally whereas I
> > > need Parent-Child format.
> > >
> > > --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> > > <mailto:flexcoders%40yahoogroups.com> , Alex Harui <aharui@> wrote:
> > > >
> > > > What happens if you just pass the XMLList to the MenuBar?
> > > >
> > > > If you use an ArrayCollection, each node must contain an
> > > > ArrayCollection of its child nodes.
> > > >
> > > >
> > > > On 4/2/10 9:45 AM, "md_ars" <mdars06@> wrote:
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > The XML which I am getting as the Result is given below.The row data is
> > > > defined in <item type="ns1:MTResultTuple" xmlns:ns5="http: which has
> > > > colums value as stringValue/numberValue etc.
> > > >
> > > > I am creating XMLList as
> > > > var myDBXMLLIST:XMLList = myDBXML.mtResult.tuples.item.tuple;
> > > >
> > > > where as populating ArrayCollection as following
> > > > queryData.addItem ({itemId:myDBXMLLIST[i].item.numberValue[0],
> > > > parentId:myDBXMLLIST[i].item.numberValue[1],
> > > > itemLabel:myDBXMLLIST[i].item.stringValue[2]
> > > >
> > > > myDBXML XML
> > > > <ns1:mtExecuteResponse encodingStyle="http://schemas.xmlsoap.org/soap/e
> > > > <mtResult type="ns1:MTResult" xmlns:ns1="http://www.mastertax.n
> > > > <columnDataTypes type="ns2:Array" ns2:arrayType="xsd:in
> > > > <displayableEM type="xsd:string" xmlns:ns1="http://www.
> > > > <hasOuts type="xsd:boolean" xmlns:ns1="http://www.maste
> > > > <hasTuples type="xsd:boolean" xmlns:ns1="http://www.mas
> > > > <loggableEM type="xsd:string" xmlns:ns1="http://www.mas
> > > > <names type="ns3:Array" ns3:arrayType="xsd:string[6]" x
> > > > <outs type="ns4:Array" ns4:arrayType="ns1:MTResultOutIt
> > > > <tuples type="ns5:Array" ns5:arrayType="ns1:MTResultTup
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http:
> > > > <tuple type="ns5:Array" ns5:arrayType="
> > > > <item type="ns1:VType" xmlns:ns
> > > > <item type="ns1:VType" xmlns:ns
> > > > <booleanValue type="xsd
> > > > <dateValue type="xsd:da
> > > > <numberValue type="xsd:
> > > > "0"
> > > > <stringValue type="xsd:string"
> > > > <item type="ns1:VType" xmlns:ns5="http:
> > > > <booleanValue type="xsd:boolean
> > > > <dateValue type="xsd:dateTime"
> > > > <numberValue type="xsd:decimal"
> > > > <stringValue type="xsd:string"
> > > > "File"
> > > > <item type="ns1:VType" xmlns:ns5="http:/
> > > > <booleanValue type="xsd:boolean"
> > > > <dateValue type="xsd:dateTime" nil=
> > > > <numberValue type="xsd:decimal" nil
> > > > <stringValue type="xsd:string" xmln
> > > > "TOP_LEVEL"
> > > > <item type="ns1:VType" xmlns:ns5="http://
> > > > <item type="ns1:VType" xmlns:ns5="http://
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > > <item type="ns1:MTResultTuple" xmlns:ns5="http://schemas.
> > > >
> > > > --- In [email protected] <mailto:flexcoders%40yahoogroups.com>
> > > > <mailto:flexcoders%40yahoogroups.com>
> > > > <mailto:flexcoders%40yahoogroups.com> , Alex Harui <aharui@> wrote:
> > > > >
> > > > > What does the XML look like?
> > > > >
> > > > >
> > > > > On 4/1/10 5:02 PM, "md_ars" <mdars06@> wrote:
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > The XML too will have the flat data whereas I need nested one.
> > > > > MenuBar should look like this.
> > > > >
> > > > > File List
> > > > > CustFile Transaction
> > > > > Security
> > > > > chngPwd
> > > > >
> > > > > --- In [email protected]
> > > > > <mailto:flexcoders%40yahoogroups.com>
> > > > > <mailto:flexcoders%40yahoogroups.com>
> > > > > <mailto:flexcoders%40yahoogroups.com>
> > > > > <mailto:flexcoders%40yahoogroups.com> , Alex Harui <aharui@> wrote:
> > > > > >
> > > > > > If you have XML to get an XMLList, I think you want to just use the
> > > > > > XML and not convert to an ArrayCollection
> > > > > >
> > > > > >
> > > > > > On 4/1/10 3:04 PM, "md_ars" <mdars06@> wrote:
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > Thanks Alex for the reply.
> > > > > > Before assigning it to menuBar I need to make the menu hierarchy. I
> > > > > > am parsing XMLList to ArrayCollection to get the data in the format
> > > > > > given below. I assigned that ArrayCollection to the MenuBar but it
> > > > > > gave me menu horizontally whereas I need this in hierarchy based on
> > > > > > ID and PARENT_ID values.
> > > > > >
> > > > > > ID LABEL MENU_LABEL STATUS PARENT_ID
> > > > > >
> > > > > > 1 File TOP_LEVEL ENABLED
> > > > > > 2 CustFile ROOT DISABLED 1
> > > > > > 3 Security SUB_MENU ENABLED 1
> > > > > > 5 AccessOpt ROOT DISABLED 3
> > > > > > 6 UserSetup ROOT DISABLED 3
> > > > > > 7 ChngPwd ROOT ENABLED 3
> > > > > > 9 List TOP_LEVEL ENABLED
> > > > > > 13 Locations ROOT DISABLED 9
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Alex Harui
> > > > > > Flex SDK Team
> > > > > > Adobe System, Inc.
> > > > > > http://blogs.adobe.com/aharui
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Alex Harui
> > > > > Flex SDK Team
> > > > > Adobe System, Inc.
> > > > > http://blogs.adobe.com/aharui
> > > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Alex Harui
> > > > Flex SDK Team
> > > > Adobe System, Inc.
> > > > http://blogs.adobe.com/aharui
> > > >
> > >
> >
> >
> >
> >
> >
> >
> > --
> > Alex Harui
> > Flex SDK Team
> > Adobe System, Inc.
> > http://blogs.adobe.com/aharui
> >
>
>
>
>
>
>
> --
> Alex Harui
> Flex SDK Team
> Adobe System, Inc.
> http://blogs.adobe.com/aharui
>