【发布时间】:2017-08-10 01:28:29
【问题描述】:
我将react-virtualized Grid中的简单示例修改如下。虽然这段代码有效,但我有一个两部分的问题:
- 如何修改示例,以便在
timercallback、quoteChange上 使用随机值调用。 - 如果我修改
quoteList,Grid会自动更新而不调用cellRenderer吗?
代码。我们的想法是让应用程序看起来像是在显示流式实时报价。请注意,quoteChange 目前没有做任何事情。这是我第一次尝试的微弱尝试。
import React from 'react';
import ReactDOM from 'react-dom';
import { Grid } from 'react-virtualized';
// Grid data as an array of arrays
const quoteList = [
['GE', 100, 35.28, 35.30, 100, 95125],
['IBM', 100, 135.11, 135.20, 100, 195125],
['C', 100, 45.23, 45.30, 100, 195125]
];
function quoteChange(ri, bid, ask)
{
quoteList[ri][2] = bid
quoteList[ri][3] = ask
var bi = {
columnIndex : 2,
rowIndex : ri,
}
cellRenderer(bi)
var ba = {
columnIndex : 3,
rowIndex : ri,
}
cellRenderer(ba)
}
function cellRenderer ({ columnIndex, key, rowIndex, style }) {
return (
<div
key={key}
style={style}
>
{quoteList[rowIndex][columnIndex]}
</div>
)
}
// Render your grid
ReactDOM.render(
<Grid
cellRenderer={cellRenderer}
columnCount={quoteList[0].length}
columnWidth={50}
height={quoteList.length * 20}
rowCount={quoteList.length}
rowHeight={20}
width={800}
/>,
document.getElementById('root')
);
【问题讨论】:
标签: javascript reactjs timer callback react-virtualized