代码之家  ›  专栏  ›  技术社区  ›  Mel

使用AntDesign列表和Firebase Firestore数据进行反应

  •  1
  • Mel  · 技术社区  · 5 年前

    列表的设置如下所示:

    const data = [
      {
        title: 'Ant Design Title 1',
      },
    
      <List
        itemLayout="horizontal"
        dataSource={data}
        renderItem={item => (
          <List.Item>
            <List.Item.Meta
              avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
              title={<a href="https://ant.design">{item.title}</a>}
              description="Ant Design, a design language for background applications, is refined by Ant UED Team"
            />
          </List.Item>
        )}
      />
    

    我想尝试将firebase数据放入const数据中,以便标题可以是user.name。

    {loading && <div>Loading ...</div>}
    {users.map(user => (
                <li key={user.uid}>
    

    我试图将其转换为Ant Design的列表,如下所示:

    const data = [
        {
          //title: `{user.name}`,
          title: {user.name},
    
        }
    ];
    <List
    
        itemLayout="horizontal"
        dataSource={data}
        renderItem={users.map(user => (
        // renderItem={item => (
          <List.Item>
            <List.Item.Meta
            //   avatar={<Avatar src="https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png" />}
              title={item.title}
              description="Ant Design, a design language for background applications, is refined by Ant UED Team"
            />
          </List.Item>
        ))}
      />
    

    当我尝试此操作时,会出现一个错误,显示:

    TypeError: renderItem is not a function
    

    有没有关于如何使用react将数据放入Ant设计列表的示例?

    0 回复  |  直到 5 年前
        1
  •  0
  •   Josh Pittman    5 年前

    如果你的火力基地 users 源是一个对象数组,然后直接将其添加到 dataSource 道具

      <List
        itemLayout="horizontal"
        dataSource={users}
        renderItem={item => (
          <List.Item>
            ...
          </List.Item>
        )}
      />