我有一个递归循环,如果在 ArrayCollection 的某个嵌套级别找到它应该返回值。一旦找到返回值并由函数返回,但在下一次迭代中返回值变回 null。我错过了什么或做错了什么?
// calling function
...
foundedItem = this.recursiveFindFunction(valueList);
...
private function recursiveFindFunction(items:ArrayCollection):Object
{
var retVal:Object;
for (var i:int = 0; i < items.length; i++)
{
var value:Object = items.getItemAt(i);
if (value.name == this.attribute.value.directValue as String)
{
retVal = value;
break;
}
if (value.hasOwnProperty("children"))
{
this.recursiveFindFunction(value.children);
}
}
return retVal;
}