<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
</body>
</html>
<script>
var obj = [{"tid":"8","vid":"2","name":"Finance and insurance","description":"","format":"plain_text","weight":"11","uuid":"046407e3-e150-48a1-ae9c-5b98278719ec","parent":"0","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/8"},{"tid":"29","vid":"2","name":"Astronomy","description":"","format":"plain_text","weight":"6","uuid":"a5f418f1-c7e6-42ca-ae98-cfcb59ec6486","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/29"},{"tid":"16","vid":"2","name":"Chemistry","description":"","format":"plain_text","weight":"5","uuid":"4c471efe-162f-4902-acdd-b579b39d129c","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/16"},{"tid":"40","vid":"2","name":"Small business","description":"","format":"plain_text","weight":"4","uuid":"e68253b0-051a-48d5-9baa-39363015df5f","parent":"26","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/40"},{"tid":"15","vid":"2","name":"Biology","description":"","format":"plain_text","weight":"4","uuid":"4be4593f-3f5f-4369-8fdd-8669a45cdbf8","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/15"},{"tid":"21","vid":"2","name":"Sculpting","description":"","format":"plain_text","weight":"3","uuid":"7a81371d-aac5-4d94-a640-d680ee9d15cd","parent":"17","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/21"},{"tid":"34","vid":"2","name":"Other","description":"","format":"plain_text","weight":"3","uuid":"caf667aa-b20f-4240-bc50-0c326729e5fb","parent":"19","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/34"},{"tid":"25","vid":"2","name":"Life insurance","description":"","format":"plain_text","weight":"3","uuid":"874872ef-6417-4985-9710-a906701479d9","parent":"20","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/25"},{"tid":"45","vid":"2","name":"Jurisprudence","description":"","format":"plain_text","weight":"3","uuid":"f3562505-b759-4fb7-804b-28c35fd86d33","parent":"36","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/45"},{"tid":"19","vid":"2","name":"Education","description":"","format":"plain_text","weight":"3","uuid":"74607970-cfce-4f32-b8fb-1faf64b1ea6e","parent":"0","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/19"},{"tid":"14","vid":"2","name":"Corporate","description":"","format":"plain_text","weight":"3","uuid":"40aaf7f0-a05e-47c9-b1cb-f5258059008e","parent":"26","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/14"},{"tid":"30","vid":"2","name":"Calculus","description":"","format":"plain_text","weight":"3","uuid":"b032dae8-6ee4-4509-b57c-28edde6e0306","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/30"},{"tid":"35","vid":"2","name":"Toefl","description":"","format":"plain_text","weight":"2","uuid":"cc1879ba-d941-4ab4-8c41-a1d85929c7f8","parent":"34","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/35"},{"tid":"36","vid":"2","name":"Social Studies","description":"","format":"plain_text","weight":"2","uuid":"dba614a4-fb14-4e64-be0c-89c4b25f56c5","parent":"19","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/36"},{"tid":"32","vid":"2","name":"Retirement","description":"","format":"plain_text","weight":"2","uuid":"b631dd0d-af5f-4543-a087-78b0c948a46a","parent":"26","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/32"},{"tid":"43","vid":"2","name":"Property insurance","description":"","format":"plain_text","weight":"2","uuid":"ed46f1d4-883b-4b9a-a832-0fadee8f1773","parent":"20","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/43"},{"tid":"38","vid":"2","name":"Physics","description":"","format":"plain_text","weight":"2","uuid":"e13887ef-985c-45bd-ac7a-111d0480a174","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/38"},{"tid":"18","vid":"2","name":"Other","description":"","format":"plain_text","weight":"2","uuid":"6c6300fc-03c2-4aee-bdd7-0854f39a2128","parent":"8","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/18"},{"tid":"42","vid":"2","name":"Guitar","description":"","format":"plain_text","weight":"2","uuid":"e9519df6-a97f-4722-ac06-67b41047b10b","parent":"17","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/42"},{"tid":"33","vid":"2","name":"Geography","description":"","format":"plain_text","weight":"2","uuid":"b912a594-0721-4bda-bdb2-e8e165800002","parent":"36","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/33"},{"tid":"24","vid":"2","name":"Analytics","description":"","format":"plain_text","weight":"2","uuid":"85e93dc3-d1f8-4c08-b323-97dcc62b7c29","parent":"18","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/24"},{"tid":"37","vid":"2","name":"Tutoring","description":"","format":"plain_text","weight":"1","uuid":"de9060bb-3b77-475b-b66c-abb943bf5d50","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/37"},{"tid":"10","vid":"2","name":"Tax return","description":"","format":"plain_text","weight":"1","uuid":"2ead4d97-a9a1-4c6c-8be6-d1ab4596a89b","parent":"26","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/10"},{"tid":"39","vid":"2","name":"Stock markets","description":"","format":"plain_text","weight":"1","uuid":"e201de51-dbbe-4626-accf-7b4f8715c30b","parent":"18","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/39"},{"tid":"31","vid":"2","name":"Piano","description":"","format":"plain_text","weight":"1","uuid":"b592aa46-1c66-4b02-8870-f03eadd6b0c8","parent":"17","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/31"},{"tid":"13","vid":"2","name":"Javascript","description":"","format":"plain_text","weight":"1","uuid":"3a69b757-b8fd-417b-bdd6-9856e0e3d745","parent":"34","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/13"},{"tid":"20","vid":"2","name":"Insurance","description":"","format":"plain_text","weight":"1","uuid":"7740c688-afef-4faf-8da8-27c28c63063e","parent":"8","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/20"},{"tid":"28","vid":"2","name":"Economy","description":"","format":"plain_text","weight":"1","uuid":"9804d599-9ee1-42d9-86d1-78ed56b10d01","parent":"36","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/28"},{"tid":"12","vid":"2","name":"Auto insurance","description":"","format":"plain_text","weight":"1","uuid":"39347db7-11f8-41e1-a15b-33f4d765dcda","parent":"20","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/12"},{"tid":"17","vid":"2","name":"Art","description":"","format":"plain_text","weight":"1","uuid":"5cf10d30-70a6-4ab4-b600-1d4088408166","parent":"19","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/17"},{"tid":"11","vid":"2","name":"Science","description":"","format":"plain_text","weight":"0","uuid":"377f5479-40c2-48d9-865b-845639e05fea","parent":"19","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/11"},{"tid":"46","vid":"2","name":"Programming","description":"","format":"plain_text","weight":"0","uuid":"f75007da-7cfc-4588-91b2-7b582779c463","parent":"34","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/46"},{"tid":"41","vid":"2","name":"Math","description":"","format":"plain_text","weight":"0","uuid":"e91dfbdf-7b0c-469d-ae81-2a91c68a1f1f","parent":"11","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/41"},{"tid":"44","vid":"2","name":"Investments","description":"","format":"plain_text","weight":"0","uuid":"ef4af7ba-79d7-41cd-a964-6950f9971ea0","parent":"26","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/44"},{"tid":"27","vid":"2","name":"History","description":"","format":"plain_text","weight":"0","uuid":"91d54e55-3b96-4aea-8062-e7e49b2040e7","parent":"36","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/27"},{"tid":"22","vid":"2","name":"Health insurance","description":"","format":"plain_text","weight":"0","uuid":"7b1f8a7d-1347-419d-a32b-1d3d58422cc6","parent":"20","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/22"},{"tid":"26","vid":"2","name":"Finance","description":"","format":"plain_text","weight":"0","uuid":"913f10d8-4a38-4e8e-8f7a-d5c65f5fb523","parent":"8","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/26"},{"tid":"23","vid":"2","name":"Drawing","description":"","format":"plain_text","weight":"0","uuid":"8249d420-1c31-4d9e-a93a-a4798fefa88e","parent":"17","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/23"},{"tid":"9","vid":"2","name":"Business planning","description":"","format":"plain_text","weight":"0","uuid":"2dbf4b77-0acb-4a9c-8334-6ce7bde85360","parent":"18","uri":"https://api-zhilongy.poy.cn/api/taxonomy_term/9"}]
function toTree(data) {
data.forEach(function(item) {
delete item.children;
});
// console.log(data)
var map = {};
data.forEach(function(item) {
map[item.tid] = item;
});
// console.log(map)
var val = [];
data.forEach(function(item) {
var parent = map[item.parent];
if (parent) {
(parent.children || (parent.children = [])).push(item);
} else {
val.push(item);
}
});
return val;
}
function compare(obj1, obj2) {
var val1 = Number(obj1.weight);
var val2 = Number(obj2.weight);
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
let datalist = toTree(obj)
datalist.sort(compare).forEach(a=>{
a.children.sort(compare).forEach(b =>{
b.children.sort(compare)
})
})
console.log(datalist)
</script>
//需要根据自己的需求改
- js List<Map> 将偏平化的数组转为树状结构并排序
数据格式: [ { "id":"d3e8a9d6-e4c6-4dd8-a94f-07733d3c1b59", "parentId":&quo ...
- JQuery 树状结构 jQuery-treeview.js 插件
由简入繁实现Jquery树状结构 在项目中,我们经常会需要一些树状结构的样式来显示层级结构等,比如下图的样式,之前在学.net的时候可以直接拖个服务端控件过来直接使用非常方便.但是利用Jquery的一 ...
- 由简入繁实现Jquery树状结构
在项目中,我们经常会需要一些树状结构的样式来显示层级结构等,比如下图的样式,之前在学.net的时候可以直接拖个服务端控件过来直接使用非常方便.但是利用Jquery的一些插件,也是可以实现这些效果的,比 ...
- 原生JS实现树状结构列表
树状结构列表,这个技术点之前有写过了,是基于vue讲解,但似乎都没有解决痛点,最基础的原生JS该怎么实现呢? 这篇文章会全面详细的介绍树状结构列表的实现,从数据处理成树状结构,到动态生成dom节点渲染 ...
- python 生成 树状结构
树状结构: 字典里只有一个键值对, key 为根, 值为一个列表, 列表里的某个或多个元素可以再进行分支(分支还是列表) 比如: 邮件的发件人, 收件人, 转发关系树状结构 forwarding_re ...
- js 每日一更(数组转换成前端更容易解析的树状结构)
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- 分享使用NPOI导出Excel树状结构的数据,如部门用户菜单权限
大家都知道使用NPOI导出Excel格式数据 很简单,网上一搜,到处都有示例代码. 因为工作的关系,经常会有处理各种数据库数据的场景,其中处理Excel 数据导出,以备客户人员确认数据,场景很常见. ...
- 浅谈oracle树状结构层级查询之start with ....connect by prior、level及order by
浅谈oracle树状结构层级查询 oracle树状结构查询即层次递归查询,是sql语句经常用到的,在实际开发中组织结构实现及其层次化实现功能也是经常遇到的,虽然我是一个java程序开发者,我一直觉得只 ...
- 浅谈oracle树状结构层级查询测试数据
浅谈oracle树状结构层级查询 oracle树状结构查询即层次递归查询,是sql语句经常用到的,在实际开发中组织结构实现及其层次化实现功能也是经常遇到的,虽然我是一个java程序开发者,我一直觉得只 ...
随机推荐
- 解决ASP.NET中Redis 每小时6000次访问请求的问题
原文:解决ASP.NET中Redis 每小时6000次访问请求的问题 虽然ServiceStack v4是商业支持的产品,但我们也允许免费使用小型项目和评估目的.上面的NuGet包中包含可以使用许可证 ...
- 【iOS发展-89】UIGestureRecognizer完整的旋转手势识别、缩放和拖拽等效果
(1)效果 (2)代码 http://download.csdn.net/detail/wsb200514/8261001 (3)总结 --先依据所需创建不同类型的手势识别.比方: UITapGest ...
- 潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据
原文:潜移默化学会WPF(难点控件treeview)--改造TreeView(CheckBox多选择版本),递归绑定数据 目前自己对treeview的感慨很多 今天先讲 面对这种 表结构的数据 的其中 ...
- WPF自定义控件步骤
1 .在类库里面添加system.xaml的引用,给控件指定Name: 2.设计控件的外观,并将内部元素绑定到控件类的属性:此时即使没有在类中增加相关属性也不会报错,xaml类似html错误只是不显示 ...
- 前端PS常用切图技巧
前言:前端涉及到的 ps 操作不算复杂,基本上就是切图,本文总结了常用的几种切图技巧. 工具:photoshop cs6 . photoshop cc 1. 传统切图 01 这是最笨的一种方法,核心就 ...
- SignalR的简单实现(一)
原文:SignalR的简单实现(一) ASP.NET SignalR是ASP.NET开发人员的一个新库,它使您的应用程序添加实时Web功能变得非常简单.什么是"实时网络"功能?能够 ...
- EF CodeFirst数据迁移与防数据库删除
1 开启migrations功能 enable-migrations -force 2 添加迁移版本 add-migration 名称后缀 我们每次修改实体后,都应该使用这个add-migration ...
- painter半透明的 底层窗口全透明背景
- Hadoop 3、Hadoop 分布式存储系统 HDFS(好多彩色图)
HDFS是Hadoop Distribute File System 的简称,也就是Hadoop的一个分布式文件系统. 一.HDFS的优缺点 1.HDFS优点: a.高容错性 .数据保存多个副本 .数 ...
- Oracle 裁掉北京研发团队,相应职位撤回美国(收购了NetSuite,LogFire,Dyn)
根据中国日报报道,2017年1月14日上午9点09分,甲骨文北京研发团队的同事收到了来自BU老大的一封邮件.邮件上提及,由于市场变化,甲骨文开始整合各研发中心资源公司在云计算方向发力,文末单独提出了甲 ...