0

I'm having the recursion loop of which should return value if it's found at some nested level in ArrayCollection. Once return value is found and returned by function but in next iteration return value becomes back to null. What I'm missing or doing wrong?

// 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;
}  

1 Answer 1

1

You are not catching the return of the recursive call anywhere

You are not checking the return value here

 if (value.hasOwnProperty("children"))
    {
            this.recursiveFindFunction(value.children);
    }   

A possible fix would be adding a return statement as such:

 if (value.hasOwnProperty("children"))
    {
            return this.recursiveFindFunction(value.children);
    } 

(notice the return)

Sign up to request clarification or add additional context in comments.

2 Comments

@FinFlex what ended up being the issue?
This is so old i can't remember how this ended up.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.