React Virtualized List 滚出视图

React Virtualized List scrolling out of view

我有一个可用的虚拟滚动网格,用于在页面上按部分显示文档。我现在为搜索结果添加了另一个 RV,但由于某种原因,当我向下滚动时,内容滚出视图!!我试图将其简化为仅使用具有预定高度的列表并消除潜在因素,但它仍然给了我这个奇怪的错误。代码本身按预期工作,是列表起作用了。 (我实际上是在使用 Cell Measurer 来获取行高,但即使使用以下版本,它也会起作用)。 这是代码:

const rowRenderer = ({ index, isScrolling, style, key  }) => 
  this.resultRowRenderer(index, key, style, curList)

resultRowRenderer(index, key, style, list) {
  ...
  return <Markup content={quote} onClick={() => jumpToLocCallback(location)} />       
}

render() {
  ...
  const renderList = (curList, i) => {
    const rowCount = curList.results.length

    return (
      <List
        key={i}
        height={100}
        rowHeight={30}
        rowCount={rowCount}
        rowRenderer={rowRenderer}
        overscanRowCount={0}
        width={700}
        ref={(ref) => this.List = ref}
      />
    )
  }

  const renderLists = searchResultsLists.map(renderList)

  return (
    <div className='results-sidebar'>
      {renderLists}
    </div> 
  )
}

谢谢

but for some reason the contents scroll out of view when I scroll down!!

这几乎总是由缺少 style 值引起的。 (参见 here。)

在你的情况下,你应该改变这个:

resultRowRenderer(index, key, style, list) {
  quote = '...'
  return <Markup content={quote} onClick={() => jumpToLocCallback(location)} />
}

为此:

resultRowRenderer(index, key, style, list) {
  quote = '...'
  return (
    <Markup
      content={quote}
      key={key}
      onClick={() => jumpToLocCallback(location)}
      style={style}
    />
  )
}

注意添加的 keystyle 属性。 ;)