递归函数获取索引

 renderItems = (data, index = [], bread = []) => {
    return data.map((item, i) => {
      item.index = [...index, i + 1]
      item.bread = [...bread, {
        title: item.name,
        path: item.path,
      }]
      if (item.children) {
        return (
          
{item.name}
>
{this.renderItems(item.children, item.index, item.bread)}
); } return (
{item.index.length <= 1 && } {item.index.length > 1 && } {item.name}
) }) }

你可能感兴趣的:(递归函数获取索引)