简体   繁体   English

如何解决React虚拟化(无限加载程序)中的rowCount问题

[英]How to fix the rowCount problem in react-virtualized (infinite loader)

I'm setting up a react-virtualized Infinite loader in my project but i have a little problem. 我在我的项目中设置了一个反应虚拟的无限加载器,但是我有一个小问题。 So i haven't got the remoteRowCount so i found one solution, like this: 所以我还没有remoteRowCount,所以我找到了一个解决方案,像这样:

public rowCount = this.props.hasNextPage ? this.props.list.length + 1 : this.props.list.length;

But this doesn't work for me. 但这对我不起作用。 I tried to debug why not working , but i dont found nothing. 我试图调试为什么不起作用,但是我什么也没发现。

p p

public rowCount = this.props.hasNextPage ? this.props.list.length + 1 : this.props.list.length; 

<InfiniteLoader
        rowCount={this.rowCount}
        isRowLoaded={({ index }) => !!this.props.list[index]}
        loadMoreRows={this.props.loadMoreRows}
        minimumBatchSize={10}
        threshold={5}
      >
        {({ onRowsRendered, registerChild }) => (
          <WindowScroller>
            {({ height, isScrolling, onChildScroll, scrollTop }) => (
              <AutoSizer disableHeight>
                {({ width }) => (
                  <List
                    ref={list => {
                      this.listRef = list;
                      registerChild(list);
                    }}
                    onRowsRendered={onRowsRendered}
                    autoHeight
                    width={width}
                    height={height}
                    rowCount={this.props.list.length}
                    rowHeight={56}
                    rowRenderer={this.rowRenderer}
                    overscanRowCount={0}
                    isScrolling={isScrolling}
                    onScroll={onChildScroll}
                    scrollTop={scrollTop}
                  />
                )}
              </AutoSizer>
            )}
          </WindowScroller>
        )}
      </InfiniteLoader>

I fixed , but i want to help for you (if you have a similar problem) 我已解决 ,但我想为您提供帮助(如果您遇到类似的问题)

First off all try to understand why not work correct. 首先,请尝试理解为什么无法正常工作。 For me it has been worked correct with a arbitrary big number, but with rowCount it isn't work. 对我来说,使用任意大数字都可以正常工作,但是使用rowCount却无法正常工作。

In my project case: 在我的项目案例中:

  • First i get an initial list (componentDidMount). 首先,我得到一个初始列表(componentDidMount)。

  • Second, i figure out when i add a random number to the rowCount, it was almost good. 其次,当我向rowCount添加随机数时,我发现这几乎是一件好事。

  • Third, i tried to debug the loadMoreRows, i started with indexRange . 第三,我尝试调试loadMoreRows,我从indexRange开始。 Tadaaa, this is the problem. Tadaaa,这是问题所在。 For me the startIndex and the stopIndex it was exact same value. 对我来说, startIndexstopIndex是完全相同的值。 So i tried to figure out why? 所以我试图弄清楚为什么? And I found, because the rowCount calculator expression get the previous value, not the present value. 我发现,因为rowCount计算器表达式获得的是先前的值,而不是当前的值。

Sorry for linguistic errors 对不起,语言错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM