public List<Node> ToTreeNodes(String startId){
List<ProductType> plist = this.productTypeService.list().getRows();
List<Node> listNodes = new ArrayList<Node>();
LoadTreeNode(plist, listNodes, startId);// 生成 樹節點時,根據 pid=0的根節點 來生成
return listNodes;
}
public static void LoadTreeNode(List<ProductType> plist,List<Node> listNodes,String pid) {
for (ProductType p : plist) {
// 如果組織父id=參數
if (pid.equals(p.getParentId())) {
Map<String, String> map = new HashMap<String, String>();
map.put("url", p.getUrl());
// 將 組織轉成 樹節點
Node node = new Node(p.getId(), p.getName(), "closed",new ArrayList<Node>(),null, map);
// 注意千千萬要 new new// ArrayList<Node>();
// 將節點 加入到 樹節點集合
listNodes.add(node);
// 遞歸 爲這個新創建的 樹節點找 子節點
LoadTreeNode(plist, node.getChildren(), node.getId());
}
}
}