本文介绍了当点击树中的一个项目时,它会使垂直滚动条跳起来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看看这个简单的代码

  Tree testTree = new Tree(); 
TreeItem testTreeItem = new TreeItem(test);
TreeItem testTreeItem2 = new TreeItem(test2);
more TreeItem ....

testTree.addItem(testTreeItem1);
testTree.addItem(testTreeItem2);
........

现在,调整您的浏览器的大小,以便您可以请参阅右侧的垂直滚动条。现在点击最底层的一个树项目 testTreeItem10 ,你会看到垂直滚动条跳起来而不是停留在当前位置。

使用UiBinder时也会发生这个错误

 < g:树ui:field =myTree> 
< g:TreeItem text =Item 1/>
< g:TreeItem text =Item 2/> .....
< / g:树>

另外, addItem <$ c $如何解决这个问题?

,但我不确定这是正确的方式或优雅的方式来解决?



这个黑客代码可以在未来破解吗?

顺便说一句,只需修改一下Tree:

 树testTree = new Tree(){

public void onBrowserEvent(Event event){
if(DOM.eventGetType(event)== Event.ONCLICK){

return;


if(DOM.eventGetType(event)== Event.ONMOUSEDOWN){
// int s = scrollPanel.getVerticalScrollPosition();
int scrollLeftInt = Window.getScrollLeft();
int scrollTopInt = Window.getScrollTop();
DOM.setStyleAttribute(this.getElement(),position,
fixed);
super.onBrowserEvent(event);
DOM.setStyleAttribute(this.getElement(),position,
static);

//scrollPanel.setVerticalScrollPosition(s);
Window.scrollTo(scrollLeftInt,scrollTopInt);
return;
}

super.onBrowserEvent(event);
}

};


Look at this simple code

 Tree testTree=new Tree();
 TreeItem testTreeItem=new TreeItem("test");
 TreeItem testTreeItem2=new TreeItem("test2");
 more TreeItem....

 testTree.addItem(testTreeItem1);
 testTree.addItem(testTreeItem2);
 ........

Now, resize your browser so that you can see the vertical scroll bar on the right hand-side. Now click on a tree item at the very bottom ex testTreeItem10, you will see the the vertical scroll bar jump up instead of staying in the current position.

This error also happens when using UiBinder

<g:Tree ui:field="myTree">
<g:TreeItem text="Item 1" />
<g:TreeItem text="Item 2" /> .....
</g:Tree>

Also, addItem of Tree got deprecated, so how to solve this problem?

解决方案

This hacking code may work, but i am not sure it is the right way or elegant way to fix?

Could this hacking code break in the future?

By the way, just modify the Tree a bit:

    Tree testTree=new Tree(){

        public void onBrowserEvent(Event event) {
            if (DOM.eventGetType(event) == Event.ONCLICK) {

                return;
            }

            if (DOM.eventGetType(event) == Event.ONMOUSEDOWN) {
                //int s = scrollPanel.getVerticalScrollPosition();
                int scrollLeftInt = Window.getScrollLeft();
                int scrollTopInt = Window.getScrollTop();
                DOM.setStyleAttribute(this.getElement(), "position",
                        "fixed");
                super.onBrowserEvent(event);
                DOM.setStyleAttribute(this.getElement(), "position",
                        "static");

                //scrollPanel.setVerticalScrollPosition(s);
                Window.scrollTo(scrollLeftInt,scrollTopInt);
                return;
            }

            super.onBrowserEvent(event);
        }

    };

这篇关于当点击树中的一个项目时,它会使垂直滚动条跳起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:48