React Virtualized List滚动出视图

时间:2016-12-25 18:41:08

标签: reactjs react-virtualized

我有一个工作虚拟滚动网格,用于按页面上的部分显示文档。我现在为搜索结果添加了另一个RV,但由于某种原因,当我向下滚动时内容滚动出视图!我试图简化它只是使用具有预定高度的List并消除潜在因素,它仍然给了我这个奇怪的bug。代码本身按预期工作,它是正在执行的列表。 (我实际上使用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> 
  )
}

由于

1 个答案:

答案 0 :(得分:4)

  

但由于某种原因,当我向下滚动时,内容会滚出视图!!

这几乎总是由缺少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属性。 ;)

相关问题