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

时间:2011-05-11 06:46:12

标签: javascript extjs extjs4

我的顶部工具栏中有一个带有文本字段的树状面板。击键后重新加载树,但它正在远离文本框

这是我的代码:

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}});                                                    
                    }                                       
        }}
            }       

    }]
});

1 个答案:

答案 0 :(得分:0)

一种解决方案是在store.load()上为params添加一个回调,以便在文本上调用焦点:

//***************
//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*/
    }
}});