RE: [flexcoders] Searching Multi Demensional arrays

2009-01-08 Thread Randy Martin
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: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On
Behalf Of Aaron Hardy
Sent: Monday, December 29, 2008 5:07 PM
To: flexcoders@yahoogroups.com
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 = 
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\
  [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 = l
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\l
  [6] (Object)#11
lastModified = 1230575547578
name = nnn
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\nnn
  [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
danv...@gmail.com
http://www.danvega.org

 

 



[flexcoders] Searching Multi Demensional arrays

2008-12-29 Thread Dan Vega
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 = 
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\
  [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 = l
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\l
  [6] (Object)#11
lastModified = 1230575547578
name = nnn
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\nnn
  [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
danv...@gmail.com
http://www.danvega.org


Re: [flexcoders] Searching Multi Demensional arrays

2008-12-29 Thread Aaron Hardy

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 = 
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\

  [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 = l
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\l

  [6] (Object)#11
lastModified = 1230575547578
name = nnn
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\nnn

  [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
danv...@gmail.com mailto:danv...@gmail.com
http://www.danvega.org http://www.danvega.org

 




Re: [flexcoders] Searching Multi Demensional arrays

2008-12-29 Thread Manish Jethani
On Tue, Dec 30, 2008 at 3:35 AM, Dan Vega danv...@gmail.com 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;

[snip]

You could index them by path, basically. Go through the object graph
and add each object to a map (Object) with the path property as the
key.

  map[obj.path] = obj;

Later you can access any object by its path:

  someObj = map[somePath];

This is typically how you'd do it in AS3/Flex.

Manish

-- 
Manish Jethani
http://manishjethani.com


Re: [flexcoders] Searching Multi Demensional arrays

2008-12-29 Thread ivo
since the path will be unique for each object it could serve as the key in a 
hash. 

mapPathToObj[obj1.path] = obj


only works for exact matches tho, if you are looking for substrings then you 
will need to iterate over the nodes.





From: Dan Vega danv...@gmail.com
To: flexcoders@yahoogroups.com
Sent: Monday, December 29, 2008 2:05:19 PM
Subject: [flexcoders] Searching Multi Demensional arrays


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 = 
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\ 
  [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 = l
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\ l
  [6] (Object)#11
lastModified = 1230575547578
name = nnn
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\ nnn
  [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
danv...@gmail. com
http://www.danvega. org


Re: [flexcoders] Searching Multi Demensional arrays

2008-12-29 Thread Dan Vega
 I am grabbing these values from a server side service like so

var dirs:Array = event.result as Array;

So in the end with an endless amount of children am I still going to have to
loop through everything to map them as they come in?


Thank You
Dan Vega
danv...@gmail.com
http://www.danvega.org