请教 react 的 list 渲染问题

2022-09-05 22:59:29 +08:00
 sealingpp
    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);
507 次点击
所在节点    问与答
4 条回复
sealingpp
2022-09-05 23:01:10 +08:00
这样写法有问题? 为何得到如此结果?
http://towncloud.sea8.top/index.php/s/9SiiHM9TfbNtNIn
lalalaqwer
2022-09-05 23:08:37 +08:00
箭头函数带大括号要 return
westoy
2022-09-05 23:08:46 +08:00
map 里都没 return

{}里要显性 return 的啊
sealingpp
2022-09-05 23:11:41 +08:00
@lalalaqwer
@westoy
明白了,感谢

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/877937

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX