【发布时间】:2010-03-21 16:23:04
【问题描述】:
是否有可能在 ArrayCollection 中获取项目的深度?
【问题讨论】:
标签: apache-flex arrays collections depth
是否有可能在 ArrayCollection 中获取项目的深度?
【问题讨论】:
标签: apache-flex arrays collections depth
来自livedocs:
// Get the index of the item with the value ME.
var addedItemIndex:int=myAC.getItemIndex("ME");
【讨论】:
这是我的代码...
public function getItemNestLevel(needle:Object, haystack:Object, level:Number = 0):Number
{
//iterate through items
for each (var item:Object in haystack)
{
if (item == needle)
{
return level;
}
//iterate through item's properties
for each (var child:Object in item)
{
if (child is Array || child is ArrayCollection)
{
var lvl:Number = level + 1;
var num:Number = getItemNestLevel(needle, child, lvl);
if (num >= 0)
{
return num;
}
}
}
}
return -1;
}
【讨论】:
不是答案,我不能发布 cmets。
来自实时文档:http://livedocs.adobe.com/flex/3/langref/mx/collections/ArrayCollection.html
ArrayCollection 类是一个包装器 将数组公开为 可以访问的集合和 使用方法和操纵 ICollectionView 的属性或 IList 接口。
为什么你认为 ArrayCollection 有深度?
我猜你可以创建一个子 ArrayCollections 的 ArrayCollection。如果是这种情况;那么你可以编写一个函数来搜索它的所有子 ArrayCollections。
编辑:我认为您建议的功能存在一些错误。这是我尝试过的一个功能:
public function getItemNestLevel2(needle:Object, haystack:Object):Number
{
for each (var item:Object in haystack)
{
if (item == needle)
return 0;
if (item is Array || item is ArrayCollection)
{
var nestLevel:int = getItemNestLevel2(needle, item);
if (nestLevel >= 0)
return nestLevel + 1;
}
}
return -1;
}
【讨论】: