Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's what I ended up doing, apparently you can dynamically add new properties to an object with </p> <pre><code> object['new_prop'] = whatever </code></pre> <p>From there, I used a recursive function to iterate through any children so you could have n levels of the hierarchy and if it found anything it would pass up through the chain by reference until the original function found it and acted on it.</p> <pre><code>private function PutChildrenWithParents(accountData : ArrayCollection) : ArrayCollection{ var pos_inner:int = 0; var pos_outer:int = 0; var result:Object = new Object(); while(pos_outer &lt; accountData.length){ if (accountData[pos_outer].ParentId != null){ pos_inner = 0; while(pos_inner &lt; accountData.length){ result = CheckForParent(accountData[pos_inner], accountData[pos_outer].ParentId); if ( result != null ){ if(result.hasOwnProperty('children') == false){ result['children'] = new ArrayCollection(); } result.children.addItem(accountData[pos_outer]); accountData.removeItemAt(pos_outer); pos_inner--; } pos_inner++; } } pos_outer++; } return accountData; } private function CheckForParent(suspectedParent:Object, parentId:String) : Object{ var parentObj:Object; var counter:int = 0; if ( suspectedParent.hasOwnProperty('children') == true ){ while (counter &lt; suspectedParent.children.length){ parentObj = CheckForParent(suspectedParent.children[counter], parentId); if (parentObj != null){ return parentObj; } counter++; } } if ( suspectedParent.Id == parentId ){ return suspectedParent; } return null; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload