【问题标题】:react infinite scroll component table body反应无限滚动组件表体
【发布时间】:2020-12-09 07:41:04
【问题描述】:

有没有办法在“表格”中使用 react 无限滚动组件包? https://www.npmjs.com/package/react-infinite-scroll-component 这是我的代码。

<table className="table table-sm table-dark table-striped table-hover">
              <thead className="">
                <tr>
                  <th scope="col">#</th>
                  <th scope="col">Type</th>
                  <th scope="col">Object</th>
                  <th scope="col">Url</th>
                  <th scope="col">Ip</th>
                  <th scope="col">Detail</th>
                </tr>
              </thead>
              <tbody>
                <InfiniteScroll
                  dataLength={logs.list.length} //This is important field to render the next data
                  next={fetchData}
                  hasMore={logs.hasMore}
                  loader={<h4>Loading...</h4>}
                  endMessage={
                    <p style={{ textAlign: "center" }}>
                      <b>Yay! You have seen it all</b>
                    </p>
                  }
                >
                  {logs.list.map((l, i) => {
                    return (
                      <tr key={l.id}>
                        <th scope="row">{l.id}</th>
                        <td>{l.key}</td>
                        <td>{l.object}</td>
                        <td>{l.url}</td>
                        <td>{l.ip}</td>
                        <td>----</td>
                      </tr>
                    );
                  })}
                </InfiniteScroll>
              </tbody>
            </table>

【问题讨论】:

    标签: reactjs infinite-scroll react-infinite-scroll-component


    【解决方案1】:

    是的,您只需将&lt;InfiniteScroll&gt; 向外移动以包裹整个&lt;table&gt;,而不是将其放在&lt;tbody&gt; 内。否则,当它渲染你的加载消息时,你会得到无效的 DOM 嵌套。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 2020-08-18
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-31
    • 1970-01-01
    相关资源
    最近更新 更多