V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
sealingpp
V2EX  ›  问与答

请教 react 的 list 渲染问题

  •  
  •   sealingpp · 2022-09-05 22:59:29 +08:00 · 503 次点击
    这是一个创建于 599 天前的主题,其中的信息可能已经有所发展或是发生改变。
        export interface LeftBar {
            expanded?: boolean;
            name: string;
            children?: LeftBar[];
        }
    
      const LeftBars:LeftBar[] = [
        {
          name: '系统账号',
          children: [
            {
              name: '用户',
              children: [],
            },
            {
              name: '资源',
              children: [],
            },
          ],
        },
      ];
      const leftItems = LeftBars.map((lb) => {
        <li>{lb.name}</li>;
      });
      console.log('LeftBars', LeftBars);
      console.log('leftItems', leftItems);
    
    sealingpp
        1
    sealingpp  
    OP
       2022-09-05 23:01:10 +08:00
    这样写法有问题? 为何得到如此结果?
    http://towncloud.sea8.top/index.php/s/9SiiHM9TfbNtNIn
    lalalaqwer
        2
    lalalaqwer  
       2022-09-05 23:08:37 +08:00
    箭头函数带大括号要 return
    westoy
        3
    westoy  
       2022-09-05 23:08:46 +08:00
    map 里都没 return

    {}里要显性 return 的啊
    sealingpp
        4
    sealingpp  
    OP
       2022-09-05 23:11:41 +08:00
    @lalalaqwer
    @westoy
    明白了,感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2902 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 12:29 · PVG 20:29 · LAX 05:29 · JFK 08:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.