public List<Menu> findAll() { List<Organization> list = organizationRepository.findAll(); Map<Long, Menu> map = new HashMap<Long, Menu>(); List<Menu> mlist = new ArrayList<>(); list.stream().forEach(temp -> { Menu m = new Menu(); m.setLabel(temp.getName()); m.setId(temp.getId()); m.setUrl(""); map.put(temp.getId(), m); }); Menu root = new Menu(); root.setLabel("root"); for (int i = 0; i < list.size(); i++) { Long parentId = list.get(i).getId(); List<Menu> mchild=setMenu(Long.valueOf(parentId),map,list); Menu parent = map.get(parentId); parent.setChildren(mchild); } root.setChildren(setMenu(Long.valueOf(0),map,list)); return root.getChildren(); } public List<Menu> setMenu(Long parentId,Map<Long, Menu> map,List<Organization> list){ List<Long> child = list.stream() .filter(temp -> temp.getParentId() == parentId) .map(tmp -> tmp.getId()) .collect(Collectors.toList()); List<Menu> mchild = new ArrayList<>(); for (int j = 0; j < child.size(); j++) { mchild.add(map.get(child.get(j))); } return mchild; }
var vm =new Vue({ el: '#app', data: { content:[],visible: false, defaultProps: { children: 'children', label: 'label' }}, mounted: function () { this.getMenu(); }, methods: { getMenu: function () { this.listLoading = true; var params_ = {}; this.$http.get("/getMenu", {params: params_}).then(function (response) { console.log(response.data); this.content=response.data; }).catch(function (response) { console.error(response); }); this.listLoading = false; }, handleNodeClick :function(data) { console.log(data); } } });