当前位置: 首页 > news >正文

网站建设服务方案简述企业建设网站的必要性

网站建设服务方案,简述企业建设网站的必要性,网络推广专员岗位职责,找人搭建网站多少钱原文链接:如何将路径字符串数组(string[])转成树结构(treeNode[])? 需求 这里的UI使用的是Element-Plus。 将一个路径字符串数组(当然也可能是其他目标字符串数组),渲染成树。 /*source:/a/b/c/d/e/a/b/e/f/g/a/b/h/a…

原文链接:如何将路径字符串数组(string[])转成树结构(treeNode[])?

需求

这里的UI使用的是Element-Plus

将一个路径字符串数组(当然也可能是其他目标字符串数组),渲染成

/*source:/a/b/c/d/e/a/b/e/f/g/a/b/h/a/i/j/a/i/kwhat I need:a/   \b     i/|\   / \c e h j   k| |d f| |e g   */

这里模拟了待转化的字符串数组如下:

let TargetKeyLists = ["D:\\$RECYCLE.BIN\\S-1-5-21-2980625316-768050560-104202119-1001\\$I0KVI2C.css","D:\\$RECYCLE.BIN\\S-1-5-21-2980625316-768050560-104202119-1001\\$I61JY0M.php","D:\\$RECYCLE.BIN\\S-1-5-21-2980625316-768050560-104202119-1001\\$I8IC15E.html","D:\\$RECYCLE.BIN\\S-1-5-21-2980625316-768050560-104202119-1001\\$I9UTNI9.ico","D:\\Program Files\\Sandboxie","D:\\fbs\\xampp-windows-x64-8.2.0-0-VS16-installer.exe","D:\\fcstor\\.svn","D:\\xampp\\MercuryMail","D:\\xampp\\anonymous","D:\\xampp\\apache","C:\\$Recycle.Bin\\S-1-5-18","C:\\$Recycle.Bin\\S-1-5-21-2980625316-768050560-104202119-1001","C:\\$Recycle.Bin\\S-1-5-21-2980625316-768050560-104202119-500","C:\\BOOTNXT",
]

转化后的目标结构如下:

[{"label": "D:","children": [{"label": "$RECYCLE.BIN","children": [{"label": "S-1-5-21-2980625316-768050560-104202119-1001","children": [{"label": "$I0KVI2C.css","children": []},{"label": "$I61JY0M.php","children": []},{"label": "$I8IC15E.html","children": []},{"label": "$I9UTNI9.ico","children": []}]}]},{"label": "Program Files","children": [{"label": "Sandboxie","children": []}]},{"label": "fbs","children": [{"label": "xampp-windows-x64-8.2.0-0-VS16-installer.exe","children": []}]},{"label": "fcstor","children": [{"label": ".svn","children": []}]},{"label": "xampp","children": [{"label": "MercuryMail","children": []},{"label": "anonymous","children": []},{"label": "apache","children": []}]}]},{"label": "C:","children": [{"label": "$Recycle.Bin","children": [{"label": "S-1-5-18","children": []},{"label": "S-1-5-21-2980625316-768050560-104202119-1001","children": []},{"label": "S-1-5-21-2980625316-768050560-104202119-500","children": []}]},{"label": "BOOTNXT","children": []}]}
]

步骤

1.在utils文件夹下新建index.ts文件。

interface TreeNode {label: stringchildren: TreeNode[]
}// 循环构建子节点
const buildChildrenNode = (children: TreeNode[], nodeArray: string[]) => {for (let i in nodeArray) {let _i: number = Number(i)let node: TreeNode = {label: nodeArray[_i],children: []}if (_i != nodeArray.length) {node.children = []}if (children.length == 0) {children.push(node)}let isExist = falsefor (let j in children) {if (children[j].label == node.label) {if (_i != nodeArray.length - 1 && !children[j].children) {children[j].children = []}children = _i == nodeArray.length - 1 ? children : children[j].childrenisExist = truebreak}}if (!isExist) {children.push(node)if (_i != nodeArray.length - 1 && !children[children.length - 1].children) {children[children.length - 1].children = []}children = _i == nodeArray.length - 1 ? children : children[children.length - 1].children}}
}
/*** @description: string[] ->  treeNode[]* @param {string} list 资源路径数组* @param {string} clientLabel 是否需要在最外面还要套一层(exam:所属客户端)* @return { treeNode[] }*/
export const array2Tree = (list: string[], clientLabel?: string) => {let targetList: TreeNode[] = []list.map(item => {let label = itemlet nodeArray: string[] = label.split('\\').filter(str => str != '')// 递归let children: TreeNode[] = targetList// 构建根节点if (children.length == 0) {let root: TreeNode = {label: nodeArray[0],children: []}if (nodeArray.length > 1) {root.children = []}children.push(root)buildChildrenNode(children, nodeArray)} else {buildChildrenNode(children, nodeArray)}})if (!clientLabel) {return targetList} else {const newArr = [{label: clientLabel,children: targetList}]return newArr}
}

2.在目标页面中引入并调用array2Tree方法即可。

<template><el-tree :data="confirmTreeList" default-expand-all />
</template>
import { array2Tree } from '@/utils/index'let confirmTreeList: TreeNode[] = []confirmTreeList = array2Tree(TargetKeyLists)

3.效果如下:

这里说明一下,array2Tree()方法中的clientLabel参数其实可要可不要,也可继续扩展,根据自身业务而定。

比如我想最后实现的效果如下图所示:

所以在第2步中传入clientLabel即可:

confirmTreeList = array2Tree(TargetKeyLists,'test(192.168.0.213)')
http://www.bjxfkj.com.cn/article/110729.html

相关文章:

  • 怎么建立淘宝客网站企业查询哪个软件是免费的
  • 网站制作与管理技术...网站建设服务器对比
  • 复古风格网站王烨
  • 顶尖的设计网站wordpress文章价格产品价格
  • Python用数据库做网站做网站jsp好还是
  • 广西网站运营中国建设银行总行官方网站
  • 烟台做网站排名wordpress模块设计
  • 怎么做网站前段wordpress设置
  • 洛江网站建设报价夏县做网站
  • 谢馥春网站建设的优势免费的企业网站cms
  • 网站demo 工具百度seo
  • 网站开发服务费算无形资产吗网页加速器插件
  • 移动端网站制作的有哪些要求网络防御中心是什么
  • dede网站微信分享封面科技与狠活
  • 网站备案费用多少怎么自己写网页
  • 泰安放心的企业建站公司网页制作用什么软件比较好
  • php+mysql网站开发全程实例 pdf开发微信小程序收费吗
  • 老河口网站定制哪家做网站最便宜
  • 网站优化站外链接怎么做网站3网合一是怎么做的
  • kotlin做网站外贸网站定制公司
  • 怎么做公司网站竞价两个人做aj的视频教程
  • 旅行社网站建设规划书单位怎样做网站
  • 国外做logo的网站wordpress主题模板百度云
  • 扬中做网站整人图片制作器
  • 音乐网站建设规划outlook企业邮箱官网
  • 做交互的设计网站柳江企业网站建设公司
  • 栗田工业大连有效公司网站哪年做的公司建设网站费用做那个科目
  • 做网站接单的网站鉴定手表网站
  • 交易所开发深圳网站制作上海注册公司买新能源车
  • 网站上社保做增员怎么做手机开发者选项