我使用flex table来显示从db获取的数据。当表格包含大量的列时,渲染弹性表格需要花费很多时间(我已经在包含80列和38行的表格上进行了测试),虽然它没有完全渲染,但我不能对页面做任何事情。因此,我按如下方式使用Schedule.get().scheduleIncremental(ReapitingCommand command)
:
final int WORK_CHUNK = 2;
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
int rowCounter = 0;
@Override
public boolean execute() {
for (int i = rowCounter; i < rowCount; i++, rowCounter++) {
for (int j = 0; j < columnCount; j++) {
table.setText(i, j, data.get(i)[j]);
}
if (rowCounter % WORK_CHUNK == 0)
return true;
}
return false;
}
});
但是如果我在data
对象中有9行3列,它只渲染2行。我如何提高它的性能,因为正如我前面所说的,如果有38行和80列,在没有scheduleIncremental
的情况下呈现所有数据会花费太多时间。甚至浏览器弹出窗口,该脚本可能已停止响应。
发布于 2011-12-10 16:59:15
为什么不使用CellTable而不是FlexTable来呈现数据呢?
与FlexTable相比,CellTable在渲染大量数据方面应该要高效得多。
发布于 2013-06-05 18:14:46
对于上面的代码,我会这样做。去掉第一个for循环,因为execute()是递归的。
Scheduler.get().scheduleIncremental(new RepeatingCommand() {
int rowCounter = 0;
int rowCount = 10;
@Override
public boolean execute() {
// do some work
for (int j = 0; j < columnCount; j++) {
table.setText(i, j, data.get(i)[j]);
}
rowCounter++;
if (rowCounter >= rowCount)
return false;
return true;
}
});
https://stackoverflow.com/questions/8456711
复制相似问题