sealingpp
V2EX  ›  问与答

请教 react 的 list 渲染问题

  •  
  •   sealingpp · Sep 5, 2022 · 1281 views
    This topic created in 1347 days ago, the information mentioned may be changed or developed.
        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
       Sep 5, 2022
    这样写法有问题? 为何得到如此结果?
    http://towncloud.sea8.top/index.php/s/9SiiHM9TfbNtNIn
    lalalaqwer
        2
    lalalaqwer  
       Sep 5, 2022
    箭头函数带大括号要 return
    westoy
        3
    westoy  
       Sep 5, 2022
    map 里都没 return

    {}里要显性 return 的啊
    sealingpp
        4
    sealingpp  
    OP
       Sep 5, 2022
    @lalalaqwer
    @westoy
    明白了,感谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1046 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 22:43 · PVG 06:43 · LAX 15:43 · JFK 18:43
    ♥ Do have faith in what you're doing.