MGWT ScrollPanel.scrollTo(0, y) 导致 Cannot read 属性 'style' of undefined

MGWT ScrollPanel.scrollTo(0, y) leads to Cannot read property 'style' of undefined

我使用 MGWT 的 ScrollPanel 并执行以下操作:

  private void scrollToBottom() {
    if (getUiHandlers().isVisible()) {
      final int height = scrollPanel.getOffsetHeight();
      final int heightInt = cellList.getOffsetHeight();
      final int y = scrollPanel.getMaxScrollY();

      if (heightInt >= height) {
          scrollPanel.scrollTo(0, y);
      }
    }
  }

说到这一行:

scrollPanel.scrollTo(0, y)

我收到以下错误:

UncaughtException: (TypeError) : Cannot read property 'style' of undefined 
UncaughtException details: setDelay_1_g$
UncaughtException details: setTransitionsDelay_0_g$ 
UncaughtException details: scrollbarPos_0_g$ 
UncaughtException details: pos_1_g$ 
UncaughtException details: execute_30_g$ 
UncaughtException details: startAnimation_0_g$ 
UncaughtException details: scrollTo_7_g$
UncaughtException details: scrollTo_6_g$
UncaughtException details: scrollTo_5_g$ 
UncaughtException details: scrollTo_3_g$ 

如何防止这个错误?

从源代码和堆栈跟踪来看,您似乎遇到了滚动条问题。当您调用 scrollTo 时,您的 mgwt 滚动面板是否总是有滚动条?

此外,我强烈建议您将 scrollPanel.scrollTo(0, y); 调用包装到 Scheduler.get().scheduleDeffered(..your scrollTo call here 此处输入代码..)

1) 确保调用 setScrollingEnabledY(true) 或 setShowVerticalScrollBar(true) 或 setShowScrollBarY(true)。

其中 none 为 (false)。

2) 滚动条仅在调用 scrollPanel.refresh() 时初始化,当 ScrollPanel 附加到 DOM.

2a) 所以请确保在将 ScrollPanel 添加到 DOM 之前 而不是 调用 scrollTo .

2b) And 将 scrollTo 调用包装在 timer.schedule(1) 中以解决 onAttach() 中的异步调用。