如何使用 js 实现一个树组件

tree component



const arr = [
{
id: 1,
value: 1,
level: 1,
parentId: 0,
},
{
id: 2,
value: 2,
level: 1,
parentId: 0,
},
{
id: 3,
value: 3,
level: 2,
parentId: 1,
},
{
id: 4,
value: 4,
level: 2,
parentId: 1,
},
{
id: 5,
value: 5,
level: 3,
parentId: 2,
},
]; const obj = {
root: {
id: 0,
value: 0,
level: 0,
parentId: 0,
children: null,
},
} const json = {
root: {
id: 0,
value: 0,
level: 0,
parentId: 0,
children: [
{
id: 1,
value: 1,
level: 1,
parentId: 1,
children: [
{
id: 3,
value: 3,
level: 2,
parentId: 2,
children: [
{
id: 5,
value: 5,
level: 3,
parentId: 2,
children: null,
},
],
},
{
id: 4,
value: 4,
level: 2,
parentId: 2,
children: null,
},
],
},
{
id: 2,
value: 2,
level: 1,
parentId: 1,
children: null,
},
]
}
} const tree = {
"root": {
"id": null,
"title": "root",
"expanded": true,
"folder": true,
"selected": false,
"children": [
{
"id": null,
"title": "backend-publish/libs/layui-src/images/face/54.gif",
"expanded": true,
"folder": false,
"selected": false,
"children": null
},
{
"id": null,
"title": "backend-publish/libs/layui-src/images/face/54.gif",
"expanded": true,
"folder": false,
"selected": false,
"children": null
},
],
},
}

JSON.stringify

JSON.stringify(value[, replacer[, space]])

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify


const log = console.log; const obj = {
a: "a",
b: {
c: "c",
d: {
e: "e",
f: {
g: "g",
h: {
i: "i",
},
},
},
},
};
// OK
log(`obj nested =\n`, JSON.stringify(obj, null, 2));
// log(`obj nested =\n`, JSON.stringify(obj, null, 4));
// 隐藏 bug
// log(`obj nested =\n`, JSON.parse(JSON.stringify(obj)));

refs



xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


最新文章

  1. border:none;与border:0;的区别
  2. Java Gradle入门指南之gretty插件(安装、命令与核心特性)
  3. 【Tree 3】树形结构数据加载的思考
  4. PHP中的 extends与implements 区别 [转]
  5. oracle密码文件管理
  6. linux bash: sqlplus: command not found 错误处理
  7. JAVA调用易信接口向指定好友推送消息(二)POST测试
  8. erl0001-Erlang 设计原则 process port io
  9. 关于Eclipse(MyEclipse)中一次性批量导入多个项目Project.
  10. oracle report err:REP-2103 PL/SQL formula returned invalid value or no value
  11. iOS - UITableViewCell Custom Selection Style Color
  12. 随滚动条滚动的居中div
  13. 3 分钟的高速体验 Apache Spark SQL
  14. 二、WCF应用的通信过程
  15. [HNOI2004]宠物收养场 Treap前驱后继
  16. Nginx实战之反向代理WebSocket的配置实例
  17. vue项目基本流程
  18. [C#] C# 知识回顾 - Lambda
  19. MySQL中的information_schema数据库表说明
  20. 访问GitLab的PostgreSQL数据库-(3)

热门文章

  1. Linux的.a、.so和.o文件 windows下obj,lib,dll,exe的关系 动态库内存管理 动态链接库搜索顺序 符号解析和绑定 strlen函数的汇编实现分析
  2. STM32 定时器详细篇(基于HAL库)
  3. 「笔记」数位DP
  4. 题解【CF1444A Division】
  5. Prometheus自定义监控内容
  6. Java方式导出EXCEL表格
  7. centos6.5升级gcc 4.4.7为最新版4.9.1
  8. c++复习笔记(2)
  9. 26.Apache
  10. ElasticSearch 介绍、Docker安装以及基本检索第三篇