mcya / JavaScriptExperience

👮 JavaScript Experience for web(JavaScript归类:简单入门+数组+经典循环+字符串+函数+Date日期+简单对象+BOM+DOM) +[ Issues(js实用技巧)]
29 stars 8 forks source link

项目开发:树形组件遍历 #32

Open mcya opened 6 years ago

mcya commented 6 years ago

带 children 的遍历方式~ rect项目

const renderTreeNodes = (data = []) => (data.length === 0 ? null : data.map((item = {}) => {// 树形组件遍历
      // return data.map((item) => {
        if (item.children) {
          return (
            <TreeNode title={(item.spreadname&&item.spreadname!==undefined&&item.spreadname!==null&&item.spreadname!=='')?item.spreadname:item.projname} key={item.projid} dataRef={item}>
              {renderTreeNodes(item.children)}
            </TreeNode>
          );
        }
        return <TreeNode {...item} />;
      // });
    }));
return <TreeNode {...item} />;
mcya commented 6 years ago
const renderTreeNodes = (data = []) => (data.length === 0 ? null : data.map((item = {}) => {// 树形组件遍历
        if (item.children) {
          return (
            <TreeNode title={item.projname} key={item.projid} dataRef={item}>
              {renderTreeNodes(item.children)}
            </TreeNode>
          );
        }
        return <TreeNode {...item} />;
    }));