问题描述
我在GWT中使用CellTable,并试图在某些事件发生时向行添加样式.添加样式的代码如下:
I am using a CellTable in GWT and trying to add styling to a row whenever certain events happen. The code to add styling is as follows:
Range range = playlistTable.getVisibleRange();
int start = range.getStart();
for (int i = start; i < start + playlistTable.getPageSize(); i++) {
if (playlistData.get(i) == currentSong) {
playlistTable.getRowElement(i).addClassName("highlightRow");
} else {
playlistTable.getRowElement(i).removeClassName("highlightRow");
}
}
加载应用程序并显示单元格表的第一页时,一切正常.但是,当我滚动到下一页并调用上面的代码时,GWT会抛出IndexOutOfBoundsException.当我调用getRowElement时,它不喜欢我的索引,只有在索引不在当前页面上"时才会发生.好像getRowElement始终认为当前页面是第一页.如果我滚动回到第一页,则一切正常.有人遇到过吗?我是否缺少某些东西,或者这是GWT中的错误?
When the app loads and the first page of the cell table is displayed, everything works perfectly. However when I scroll to the next page and make a call to the above code, GWT throws an IndexOutOfBoundsException. It does not like my index when I make the call to getRowElement, which only occurs if the index is "not on the current page." It's as though getRowElement always thinks the current page is the first page. If I scroll back to the first page, everything behaves fine. Has anybody encountered this? Am i missing something or is this a bug in GWT?
推荐答案
我怀疑问题在于有效页面上的 start
为 0
.如果您执行 playlistTable.getRowElement(i-start)
会怎样?您可能必须将 +1
或 -1
放在某个地方.
I suspect the problem is that start
is 0
on the page that works. What happens if you do playlistTable.getRowElement(i - start)
? You may have to throw a + 1
or a - 1
in somewhere.
这篇关于GWT CellTable getRowElement抛出IndexOutOfBoundsException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!