Try this:
Public function findPath(items:Array, mypath:String): Object {
var mySort:Sort = new Sort();
var myItems:ArrayCollection = new ArrayCollection(items);
var itemCursor:IViewCursor = myItems.createCursor();
mySort.fields = [new SortField("path")];
myItems.sort = mySort;
myItems.refresh();
itemCursor.findAny({path:mypath});
return itemCursor.current;
}
HTH,
~randy
From: [email protected] [mailto:[email protected]] On
Behalf Of Aaron Hardy
Sent: Monday, December 29, 2008 5:07 PM
To: [email protected]
Subject: Re: [flexcoders] Searching Multi Demensional arrays
I think you're looking for something like this:
public function findPath(items:Array, path:String):Object
{
for each (var item:Object in items)
{
if (item.path == path)
{
return item;
}
else if (children && children.length > 0)
{
var foundItem:Object = findPath(item.children, path);
if (foundItem)
{
return foundItem;
}
}
}
}
I didn't test out the code, but the concept is what is important. It's
recursively calling the same function for each level of children (see how it
calls findPath() within the function itself), so it digs down however deep
it needs to. Good luck.
Aaron
Dan Vega wrote:
I have an infinite number of objects & child objects that looks something
like this below. I know this if it was just one level I could probably
accomplish what i need but I am not sure how to do this. All of the "path"
items are always going to be unique. Is there a way to search (drilling down
as far as needed) and say give me the object where path = "xyz";
(Array)#0
[0] (Object)#1
children = (Array)#2
[0] (Object)#3
children = (Array)#4
lastModified = 1230587039867
name = "aaaa"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\aaaa"
[1] (Object)#5
lastModified = 1230580833728
name = "another_one"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\another_one"
[2] (Object)#6
children = (Array)#7
lastModified = 1230587312776
name = "dan"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\dan"
[3] (Object)#8
lastModified = 1230581177910
name = "ggg"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\ggg"
[4] (Object)#9
lastModified = 1230581240020
name = "hjkl"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\hjkl"
[5] (Object)#10
lastModified = 1230580116200
name = "lllll"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\lllll"
[6] (Object)#11
lastModified = 1230575547578
name = "nnnnnnn"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\nnnnnnn"
[7] (Object)#12
lastModified = 1230575859098
name = "test"
parent = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data\test"
mx_internal_uid = "B8E4886E-A00D-6D89-CBAA-84C60F791112"
name = "Home"
path = "C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\FFManager\src\data"
Thank You
Dan Vega
[email protected]
http://www.danvega.org