- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里是cellSizeAndPositionGetter
和render
我的 react 组件的函数。当我调整屏幕大小时,我的屏幕布局没有改变,但我可以通过控制台确认 width
和state.columnCount
(由 cellSizeAndPositionGetter
使用)正在改变。
是否可以触发 Collection
更新以下参数更改(即 width
)?或者我在这里做错了什么?
旁注:react-virtualized
List
确实在宽度参数更改时更新。
cellSizeAndPositionGetter({index}) {
const list = this.state.cardsList;
const columnCount = this.state.columnCount;
const columnPosition = index % (columnCount || 1);
const datum = list[index];
const height = datum.height;
const width = CELL_WIDTH;
const x = columnPosition * (GUTTER_SIZE + width);
const y = this._columnYMap[columnPosition] || 0;
this._columnYMap[columnPosition] = y + height + GUTTER_SIZE;
return ({
height,
width,
x,
y
});
}
...
render() {
return (
<div style={styles.subMain}>
<AutoSizer >
{({height, width}) => {
console.log(`width: ${width}`);
console.log(`col count: ${this.state.columnCount}`);
return (
<Collection
cellCount={this.state.cardsList.length}
cellRenderer={this.cellRenderer}
cellSizeAndPositionGetter={this.cellSizeAndPositionGetter}
height={height}
width={width}
overscanRowCount={1}
/>
);
}}
</AutoSizer>
</div>
);
}
<小时/>
更新:(几个小时后)
我发现了一个非常笨拙的解决方法来获取 react-virtualize
Collection
在宽度参数更改后更新。
当屏幕尺寸发生变化时,我会删除 Collection
列表中的最后一个元素显示元素(图像)。起初我尝试清除列表,但这会导致明显的视觉副作用。现在,在调整屏幕大小时,只有显示屏中的最终图像会奇怪地闪烁。
但是获得 Collection
仍然会很高兴更新以下width
改变。 :)
这是似乎欺骗 Collection
的代码进入更新。关键部分是setState
的第三行我删除了最后一个元素。
updateDimensions() {
this.setState({
screenWidth: window.innerWidth,
columnCount: Math.floor(window.innerWidth / (CELL_WIDTH + GUTTER_SIZE)),
cardsList: [...this.state.cardsList.slice(0, this.state.cardsList.length - 1)]
});
}
componentDidMount() {
...
window.addEventListener("resize", this.updateDimensions);
}
最佳答案
width
有变化吗意味着回流细胞? (您是否希望 Collection
内的单元格大小和位置发生变化?)如果是这样,您需要存储对 Collection
的引用。然后调用collectionRef.recomputeCellSizesAndPositions()
当width
变化。
Collection
(与所有其他 react 虚拟化组件一样)缓存大小和位置信息以提高性能。如果情况发生变化,您需要显式清除这些缓存。请参阅here和 here .
关于javascript - 当使用新的宽度和columnCount重新渲染时,如何让react-virtualized Collection进行更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41796615/
代码:
我有两个模型: MyModel ( inherits QAbstractItemModel ,它的树)和 MyProxyModel (inherits QSortFilterProxyModel)。
QTreeView忽略从QAbstractListModel继承的类的columnCount()并仅显示第一列: import sys from PyQt5.QtCore import QAbstra
我在做什么:尝试使用 onGlobalLayout() 中的 setColumnCount() 更改 GridLayout 的列数 的 OnGlobalLayoutListener() 我想达到什么目
我在很多事情上都使用 datagridview,我认为它是一个非常强大的数据查看器工具。我的问题是,我正在使用这段代码: for (int i = 0; i < dataGridView1.**Col
在 Java 中,我可以说: private double[][] data; 并初始化它: Data = new double[rowCount][columnCount] 但是,在 C# 中,我会
$sql = "CALL pr_cartItemsForCustomer (:customerId)"; $statement = $connection->prepare($s
我正在尝试在 android.support.v7.widget.GridLayout 中使用 columnCount 属性,但出现错误 错误:(2) 在包中找不到属性“useDefaultMargi
正如标题所暗示的那样,我正在尝试从结果数据集中检索表模型。我仍在学习如何使用数据库,所以我目前正在使用以下代码: import java.sql.ResultSet; import java.sql.
试图更多地了解 QAbstractTableModel,我遇到了 rowCount 和 columnCount 的虚拟方法,这些方法在继承 QAbstractTableModel 时需要实现。 拿 i
我是一名优秀的程序员,十分优秀!