reactjs - 反应递归列表深度
问题描述
我有一个像这样递归呈现的列表:
renderHeirachy(heirachy, depth) {
const list = heirachy.map((folder, index) => {
let subList;
if (folder.children && folder.children.length > 0) {
depth++;
subList = this.renderHeirachy(folder.children, depth);
}
return (
<li key={index}>
<Link className="w100 display-block" to={`?folder=${folder.slug}`}>
<span className="typcn typcn-folder mr1"></span>
{folder.name}
</Link>
{subList}
</li>
);
});
return (
<ul className={'wbbroc-list-unstyled wbbroc-list-heirachy ' + 'test'}>
{list}
</ul>
);
}
然而,问题在于,当我有多个孩子时,深度图会被抛出,例如:
ul
li -> depth = 1
li -> depth = 2
ul
li -> depth = 3
我真的只想要这样的递归深度:
ul
li -> depth = 1
li -> depth = 1
ul
li -> depth = 1
解决方案
推荐阅读
- regex - C# 正则表达式模式匹配关键字
- node.js - 数据显示在 websocket 响应中,但未显示在已解决的承诺中
- android - llvm-rs-cc 缺少颤振
- sql-server - 未显示 SQL Server Management Studio (V17.7) 功能工具提示
- sublimetext3 - 如果侧边栏打开,如何检测键绑定?
- android - 检查 json 对象是否包含特定值
- python - 正则表达式 [AZ] 不识别本地字符
- php - 如何将查询结果插入php中的数组并在另一个数组中检查它们
- https - HTTPS 的 GnuTLS 问题
- symfony - 设置数据未映射字段不起作用