ExtJs: Tree: how to scroll directly to a specific element?

后端 未结 5 440
走了就别回头了
走了就别回头了 2021-01-07 08:03

I\'m looking for a way to scroll to a specific element in a Tree. Any idea how to do this ?

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 08:41

    The DOM scrollIntoView doesn't really work as expected as it always either top or bottom aligns the element. ExtJS however seems to have just what is needed:

    Ext.get(el|elId).scrollIntoView(containerId|containerEl);
    

    For example, to ensure the currently selected item in an Ext.view.View (dataview) instance is visible, I did:

    Ext.define('MyView', {
        extend: 'Ext.view.View',
        ...
    
        listeners: {
            'selectionchange': function(_, selections) {
                if (selections.length === 1) {
                    var node = this.getNode(selections[0]);
                    Ext.fly(node).scrollIntoView(this.el);
                }
            }
        },
        ...
    }
    

提交回复
热议问题