<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    云自無心水自閑

    天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
    posts - 288, comments - 524, trackbacks - 0, articles - 6
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    Flex2中遍歷Tree節點

    Posted on 2007-01-07 14:37 云自無心水自閑 閱讀(3485) 評論(1)  編輯  收藏 所屬分類: FlexFlex2

    這個函數只是一個示例函數,演示如何遍歷一個Tree。
    此函數嚴格說起來其實是兩個函數:上半部分用于回溯父節點,下半部分遞歸遍歷子節點

    /**
    ?* This method will traverse a Tree's model independent of it's
    ?* type.
    ?*
    ?* <p>Note :: This method may look long and arduous but, rest assured
    ?* it has all the checks to perform like a champ. Also, you 'could'
    ?* refactor part of this method but, for the sake of explanation, I
    ?* kept it all in one place.</p>
    ?*
    ?* <p>Remember, I had coupled the model to this method by tracing
    ?* @label, obviously you do not need to do this. The intention of
    ?* this example is to show you that the dataDescriptor seperates
    ?* the models type and is awesome. It enables you to create a tight
    ?* method like this without type checks on the model.</p>
    ?*
    ?* @param tree The Tree instance that will be examined by the method.
    ?* @param item An item found in the dataProvider of the Tree passed in.
    ?* @param startAtParent A boolean that determines if the method upon
    ?* initialization will back up one leve3l to the item passed in and
    ?* start it's recursion at the item's parent node.
    ?*/

    public function walkTree(tree:Tree, item:Object, startAtParent:Boolean = false):void
    {
    ? ? // get the Tree's data descriptor
    ? ? var descriptor:ITreeDataDescriptor = tree.dataDescriptor;
    ? ? var cursor:IViewCursor;
    ? ?
    ? ? var parentItem:Object;
    ? ? var childItem:Object;
    ? ? var childItems:Object;
    ? ?
    ? ? // if the item is null, stop
    ? ? if(item == null)
    ? ? ? ? return;
    ? ? ? ?
    ? ? // do we back up one level to the item's parent
    ? ? if(startAtParent)
    ? ? {
    ? ? ? ? // get the parent
    ? ? ? ? parentItem = tree.getParentItem(item);
    ? ? ? ? // is the parent real
    ? ? ? ? if(parentItem)
    ? ? ? ? {
    ? ? ? ? ? ? trace("|-- Parent Node ", parentItem[tree.labelField]);
    ? ? ? ? ? ? // if the parent is a branch
    ? ? ? ? ? ? if(descriptor.isBranch(parentItem))
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? // if the branch has children to run through
    ? ? ? ? ? ? ? ? if(descriptor.hasChildren(parentItem))
    ? ? ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? ? ? // get the children of the branch
    ? ? ? ? ? ? ? ? ? ? // this part of the algorithm contains the item
    ? ? ? ? ? ? ? ? ? ? // passed
    ? ? ? ? ? ? ? ? ? ? childItems = descriptor.getChildren(parentItem);
    ? ? ? ? ? ? ? ? }
    ? ? ? ? ? ? }
    ? ? ? ? ? ? // if the branch has valid child items
    ? ? ? ? ? ? if(childItems)
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? // create our back step cursor
    ? ? ? ? ? ? ? ? cursor = childItems.createCursor();
    ? ? ? ? ? ? ? ? // loop through the items parent's children (item)
    ? ? ? ? ? ? ? ? while(!cursor.afterLast)
    ? ? ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? ? ? // get the current child item
    ? ? ? ? ? ? ? ? ? ? childItem = cursor.current;

    ? ? ? ? ? ? ? ? ? ? var label:String = childItem[tree.labelField];
    ? ? ? ? ? ? ? ? ? ? var branch:Boolean = descriptor.isBranch(childItem);
    ? ? ? ? ? ? ? ? ? ?
    ? ? ? ? ? ? ? ? ? ? // good place for a custom method()
    ? ? ? ? ? ? ? ? ? ? trace("Sibling Nodes :: ", label, "Is Branch :: ", branch);
    ? ? ? ? ? ? ? ? ? ?
    ? ? ? ? ? ? ? ? ? ? // if the child item is a branch
    ? ? ? ? ? ? ? ? ? ? if(descriptor.isBranch(childItem))
    ? ? ? ? ? ? ? ? ? ? ? ? // traverse the childs branch all the way down
    ? ? ? ? ? ? ? ? ? ? ? ? // before returning
    ? ? ? ? ? ? ? ? ? ? ? ? walkTree(tree, childItem);
    ? ? ? ? ? ? ? ? ? ? // do it again!
    ? ? ? ? ? ? ? ? ? ? cursor.moveNext();
    ? ? ? ? ? ? ? ? }
    ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? }
    ? ? else// we don't want the parent OR this is the second iteration
    ? ? {
    ? ? ? ? // if we are a branch
    ? ? ? ? if(descriptor.isBranch(item))
    ? ? ? ? {
    ? ? ? ? ? ? // if the branch has children to run through
    ? ? ? ? ? ? if(descriptor.hasChildren(item))
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? // get the children of the branch
    ? ? ? ? ? ? ? ? childItems = descriptor.getChildren(item);
    ? ? ? ? ? ? }
    ? ? ? ? ? ?
    ? ? ? ? ? ? // if the child items exist
    ? ? ? ? ? ? if(childItems)
    ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? // create our cursor pointer
    ? ? ? ? ? ? ? ? cursor = childItems.createCursor();
    ? ? ? ? ? ? ? ? // loop through all of the children
    ? ? ? ? ? ? ? ? // if one of these children are a branch we will recurse
    ? ? ? ? ? ? ? ? while(!cursor.afterLast)
    ? ? ? ? ? ? ? ? {
    ? ? ? ? ? ? ? ? ? ? // get the current child item
    ? ? ? ? ? ? ? ? ? ? childItem = cursor.current;

    ? ? ? ? ? ? ? ? ? ? var label:String =? childItem[tree.labelField];
    ? ? ? ? ? ? ? ? ? ? var branch:Boolean = descriptor.isBranch(childItem);
    ? ? ? ? ? ? ? ? ? ?
    ? ? ? ? ? ? ? ? ? ? // good place for a custom method()
    ? ? ? ? ? ? ? ? ? ? trace("-- Sub Node :: ", label, "Is Branch :: ", branch);

    ? ? ? ? ? ? ? ? ? ? // if the child item is a branch
    ? ? ? ? ? ? ? ? ? ? if(descriptor.isBranch(childItem))
    ? ? ? ? ? ? ? ? ? ? ? ? // traverse the childs branch all the way down
    ? ? ? ? ? ? ? ? ? ? ? ? // before returning
    ? ? ? ? ? ? ? ? ? ? ? ? walkTree(tree, childItem);
    ? ? ? ? ? ? ? ? ? ? // check the next child
    ? ? ? ? ? ? ? ? ? ? cursor.moveNext();
    ? ? ? ? ? ? ? ? }
    ? ? ? ? ? ? }
    ? ? ? ? }
    ? ? }
    }
    ?



    ?




    評論

    # re: Flex2中遍歷Tree節點  回復  更多評論   

    2007-02-08 11:03 by 永恒
    恩,很好的深度遍歷算法,可以再寫個廣度樹遍歷的實現
    主站蜘蛛池模板: 在线成人爽a毛片免费软件| 抽搐一进一出gif免费视频| 精品无码无人网站免费视频| 国产av无码专区亚洲av果冻传媒| 妇女自拍偷自拍亚洲精品| 国产乱子伦精品免费女| 亚洲AV综合永久无码精品天堂| 暖暖免费高清日本中文| 亚洲国产精品久久久久秋霞小| 日本a级片免费看| 国产午夜亚洲精品不卡免下载| 午夜亚洲av永久无码精品| 九九九精品视频免费| 日本亚洲国产一区二区三区| 最近的2019免费中文字幕| 亚洲一区二区女搞男| 久久精品免费观看国产| 亚洲最大黄色网站| 99久久这里只精品国产免费| 亚洲精品女同中文字幕| 免费人成在线观看网站视频 | 亚洲av永久无码天堂网| 国产裸模视频免费区无码| 性生大片视频免费观看一级| 亚洲精品国产成人片| 免费视频成人片在线观看| 久久精品亚洲AV久久久无码 | 四虎在线最新永久免费| 亚洲一区二区三区成人网站| 免费在线观看黄网| 国产精品免费观看调教网| 亚洲av成人一区二区三区| 免费大黄网站在线观| 久久免费福利视频| 亚洲色欲啪啪久久WWW综合网| 亚洲另类少妇17p| 99免费观看视频| 亚洲AV日韩综合一区| 久久精品国产精品亚洲艾| 免费下载成人电影| CAOPORN国产精品免费视频|