递归案例
案例: 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); } }
业勤于精荒于嬉
http://www.cnblogs.com/maxlei/