当一棵树加载时,它正在窃取焦点

When a tree loads it is stealing focus

本文关键字:焦点 一棵树 加载      更新时间:2023-09-26

我有一个树形面板,顶部工具栏中有一个文本字段。击键后,树被重新加载,但它会从文本框中窃取焦点

这是我的代码:

Ext.define('search_tree', {
    extend:'Ext.tree.Panel',
    rootVisible:false,
    autoScroll:true,
    store:Ext.create('Ext.data.TreeStore', {        
        root:{
            id:'node',
            nodeType:'async'           
        },
        proxy:{
            actionMethods:{
                'read':'POST'
            },
            type:'ajax',            
            url:'myurl'
        }
    }),
    tbar:['Search:', {       
        xtype:'textfield',
        id:'search_combo',        
        listeners:{
           keyup:{buffer:150,fn:function(field, e) { 
                   var val = this.getRawValue();
                   if(val.length != this.valueLength){
                        var thisTree = this.up('treepanel');
                        thisTree.store.getRootNode().removeAll();
                        //***************
                        //When this load finishes the focus is taken away
                        //From the text field  :(
                        //***************
                        thisTree.store.load({params:{search_string:val}});                                                    
                    }                                       
        }}
            }       
    }]
});

一种解决方案是在 store.load() 上向参数添加一个回调,以调用文本上的焦点:

//***************
//When this load finishes the focus is taken away
//From the text field  :(
//***************
thisTree.store.load({params:{
    search_string:val,
    callback: function() {
        this.focus(); /*or Ext.getCmp('search_combo').focus() depending on scoping*/
    }
}});