递归案例

案例:

   public void addSubFolders(ModelData parent) {
    //根据传进来的父查找子
        List<ModelData> modelList = treeStore.getChildren(parent, false);
        Log.debug("     modelList.size       "+modelList.size());
//取出子的集合判断是否为空或者size为0
        if (modelList.size() == 0) {
            return;
        }
//定义集合变量
        List<GFolder> folders = new ArrayList<GFolder>();
//遍历
        for (ModelData model : modelList) {
            Log.debug("    model       "+model);
//递归
            addSubFolders(model);
            folders.add((GFolder) model);
        }
 
        if (parent instanceof GCabinet) {
            GCabinet cabinet = (GCabinet) parent;
            Log.debug("   GCabinet    folders       "+folders);
            cabinet.setSubFolderList(folders);
        } else if (parent instanceof GFolder) {
            GFolder folder = (GFolder) parent;
            Log.debug("   GFolder    folders       "+folders);
            folder.setSubFolderList(folders);
        }
 
    }

 

 
posted @ 2016-10-12 18:54  神经质攻城狮马磊  阅读(175)  评论(0编辑  收藏  举报