码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Vue tree树状结构数据转扁平数据


    1. //数据结构可参考饿了么UI
    2. treeData: [{
    3. id: 1,
    4. label: 'Level one 1',
    5. type: 1,
    6. children: [{
    7. id: 4,
    8. label: 'Level two 1-1',
    9. type: 2,
    10. children: [{
    11. id: 9,
    12. label: 'Level three 1-1-1',
    13. type: 3
    14. }, {
    15. id: 10,
    16. label: 'Level three 1-1-2',
    17. type: 3
    18. }]
    19. }, {
    20. id: 11,
    21. label: 'Level three 1-2',
    22. type: 2,
    23. children: [{
    24. id: 12,
    25. label: 'Level three 1-2-1',
    26. type: 3
    27. }, {
    28. id: 13,
    29. label: 'Level three 1-2-2',
    30. type: 3
    31. }, {
    32. id: 14,
    33. label: 'Level three 1-2-3',
    34. type: 3
    35. }, {
    36. id: 15,
    37. label: 'Level three 1-2-4',
    38. type: 3
    39. }]
    40. }]
    41. }]
    1. //转结构(list就是你要转的树状数据)
    2. treeToList(list) {
    3. let res = []
    4. for (const item of list) {
    5. const { children, ...i } = item
    6. if (children && children.length) {
    7. res = res.concat(this.treeToList(children))
    8. }
    9. res.push(i)
    10. }
    11. return res
    12. }
    13. //查看数据是否转换成功
    14. const treeList = this.treeToList(this.treeData)
    15. console.log('树状结构转扁平结构', treeList)

    参考文档Vue tree树状结构数据转扁平数据_vue树形结构转化为平行结构-CSDN博客

  • 相关阅读:
    小程序day02
    对象池复用实践
    Python基础教程之一
    tomcat 端口 8005 被 windows 系统服务占用导致启动闪退的问题
    【PIE-Engine 数据资源】8天合成LAI产品(MOD15A2H.006)
    第十九章总结(绘制图片)
    如何使用 Tibco Business Works 6 (BW6) 或容器版 (BWCE) 创建 Restful Web 服务
    计算机专业毕业设计项目推荐04-物业管理系统(SpringBoot+原生Js+Mysql)
    前台自动化测试:基于敏捷测试驱动开发(TDD)的自动化测试原理
    lua基础之io
  • 原文地址:https://blog.csdn.net/szzlh123456789/article/details/136508997
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号