【问题标题】:MGWT ScrollPanel.scrollTo(0, y) leads to Cannot read property 'style' of undefinedMGWT ScrollPanel.scrollTo(0, y) 导致无法读取未定义的属性“样式”
【发布时间】:2016-01-26 22:49:50
【问题描述】:

我使用 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$ 

如何防止出现此错误?

【问题讨论】:

标签: javascript java html gwt mgwt


【解决方案1】:

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

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

【讨论】:

  • 它并不总是有滚动条。为什么要使用调度器?
【解决方案2】:

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

而且没有一个带有 (false)。

2) 滚动条仅在调用 scrollPanel.refresh() 时初始化,当 ScrollPanel 附加到 DOM 时,该调用在 onAttach() 中也被异步调用。

2a) 因此,请确保 将 ScrollPanel 添加到 DOM(如图所示)之前调用 scrollTo。

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

【讨论】:

  • 我在 View 的构造函数中做了scrollPanel.setScrollingEnabledX(false); scrollPanel.setShowHorizontalScrollBar(false); scrollPanel.setShowVerticalScrollBar(true); scrollPanel.setBounce(false); scrollPanel.setHideScrollBar(false);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-11-20
  • 1970-01-01
  • 2021-08-04
  • 2017-01-15
  • 2015-10-06
相关资源
最近更新 更多