extjs ExtJ 6.2.0:在页面刷新后设置文本字段的焦点

vd8tlhqk  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(77)

我试图在浏览器中重新加载/刷新页面后将焦点设置在容器中的字段上,但似乎无法找出我做错了什么。我尝试过在容器和控件本身上使用多个侦听器,但没有成功。

Ext.define('Admin.viewviewer.SearchViewTab', {
    extend: 'Ext.container.Container',
    alias: 'widget.searchviewtab',
    id: 'searchviewtab',
    title: 'Search',
    layout: {
        type: 'vbox',
        align: 'center'
    },
    defaultFocus: 'searchInputField',
    items: [
        {
            xtype: 'form',
            margin: '100px 0 0 0',
            width: 800,
            
            layout: {
                type: 'vbox',
                align: 'center'
            },
            defaults: {
                width: '100%',
            },
            items: [
                {
                    xtype: 'textfield',
                    id: 'searchInputField',
                    reference: 'searchInputField',
                    allowBlank: false,
                    msgTarget: 'under',
                    name: 'uuid',
                    bind: '{searchInput}'
                },
                {
                    xtype: 'button',
                    text: 'Execute Query',
                    formBind: true,
                    bind: {
                        text: 'Search {searchInputType}'
                    },
                    handler: 'onSearchClick',
                }
            ]
        }
    ],
    listeners: {
        afterrender: function(cmp) {
            cmp.focus(false, 200)
        }
    }
});
wyyhbhjk

wyyhbhjk1#

尝试使用textfieldafterrender侦听器。当前侦听器尝试聚焦容器,而不是文本字段:

{
    xtype: 'textfield',
    id: 'searchInputField',
    reference: 'searchInputField',
    allowBlank: false,
    msgTarget: 'under',
    name: 'uuid',
    bind: '{searchInput}',
    listeners: {
        afterrender: function(textfield) {
            textfield.focus();
        }
    }
},

注意:defaultFocus也可以工作,但它需要一个Ext.ComponentQuery,而且最好在表单上定义,而不是在外部容器上。

相关问题