0
私はArrayCollectionを持ち、各要素はTreeNode要素のArrayCollectionである "children"プロパティを持つTreeNodeクラス(私が作成したカスタムクラス)のインスタンスです。ネストされたArrayCollection要素を別のクラスに変換する
tree = new ArrayCollection([
[new TreeNode(param1, param2, new ArrayCollection([
[new TreeNode(param1, param2, null)],
[new TreeNode(param1, param2, new ArrayCollection([
[new TreeNode(param1, param2, null)],
[new TreeNode(param1, param2, new ArrayCollection([
[new TreeNode(param1, param2, null)],
[new TreeNode(param1, param2, null)]
]))],
[new TreeNode(param1, param2, new ArrayCollection([
[new TreeNode(param1, param2, null)],
[new TreeNode(param1, param2, null)]
]))]
]))]
]))],
[new TreeNode(param1, param2, null)]
]);
のTreeNodeコンストラクタは、3つのパラメータがあります:最初の二つは今重要ではありませんが、3分の1が子どもたちのプロパティ(ArrayCollectionの)で、あればそのように、私は、ArrayCollectionの構造の要素のツリーを持っていますTreeNodeに子がない場合は、そのパラメータをnullに設定する必要があります。
私は再帰的に「木」の構造を解析するために、次の関数を書いた:
private function parse(obj:Object):void {
for (var i:int = 0; i < obj.length; i++) {
if (obj[i] is TreeNode) {
if (obj[i].children != null) {
parse(obj[i].children);
}
} else {
parse(obj[i]);
}
}
}
parse(tree);
しかし、私の問題がある:私は同じ「木」構造を持っている必要があります(それは同じである必要がdoens't変数)を別のクラスのインスタンスで埋めています。それをどうすれば実現できますか?