导航栏或者菜单栏组件,元数据从最外层到 target vlaue 的路径上文案全部高亮 。所以需要找出经过 target vlaue 的路径有哪些?
const dataSource = [
{
label: '首页',
value: 1,
},
{
label: '商品分类',
value: 2,
child: [
{
label: '服饰',
value: 21,
child: [
{
label: '精美女装',
value: 211,
},
],
},
{
label: '地方特产',
value: 22,
child: [
{
label: '河南特产',
value: 221,
child: [
{
label: '方中山胡辣汤',
value: 2211,
},
{
label: '烩面',
value: 2212,
},
],
},
{
label: '上海特产',
value: 222,
},
],
}
]
},
{
label: '我的',
value: 3,
child: [
{
label: '基本信息',
value: 31,
},
{
label: '我的订单',
value: 33,
child: [
{
label: '全部订单',
value: 331,
},
{
label: '待收货',
value: 332,
},
],
}
]
}
]
/**
* 获取所有路径
*/
const getAllValuePaths = (dataSource) => {
let result = []
if (!dataSource || dataSource.length ===0) return []
const constructPaths = (data, path) => {
data.forEach(({ value, child }) => {
path.push(value)
if (!child || child.length === 0) {
result.push(JSON.parse(JSON.stringify(path)))
} else {
constructPaths(child, path)
}
path.pop()
})
}
constructPaths(dataSource, [])
return result
}
/**
* 获取指定 target 路径
*/
const getValuePathsByTarget = (dataSource, target) => {
let result = []
if (!dataSource || dataSource.length ===0 || !target) return []
const constructPaths = (data, target, path) => {
data.forEach(({ value, child }) => {
path.push(value)
if (value === target) {
result = JSON.parse(JSON.stringify(path))
return
}
if (child && child.length) {
constructPaths(child, target, path)
}
path.pop()
})
}
constructPaths(dataSource, target, [])
return result
}
一.发送效果HTML div id=send-btn button // 这里是一个svg的占位 Send /button/...
围绕数据分析与智能化技术的不断迭代创新,实现由传统BI向新型BI的转变! 我们都...
没有任何征兆的在cnBeta上看到关于TOM.COM网站改版的新闻,说是页面可以自定义了...
1.先说几个基本类型: DOMString, boolean, long, unsigned long, double, ...
实现下图的加号效果: 若想实现这个效果, 只需一个div元素即可搞定。 需要用到c...
Dreamweaver设计网页的时候,想要使用css样式,该怎么制作css样式嵌套呢?下面我...
本文介绍了用canvas画心电图的示例代码,分享给大家,具体如下: 效果图: 思路...
最近项目中涉及到一个小功能,客户在选择供应商时,由于供应商数目较多(大概300...
在本系列的第一节中,讲了 提高网站性能中网站内容有关的10条原则 。除了在网站...
对于国内很多广告主来讲,平面广告的创作和评估往往是比较主观,有的把希望寄托...