extjs4 - 如何专注于文本字段?

时间:2011-09-24 01:40:43

标签: extjs extjs4

我似乎无法将字段集中在extjs 4中的表单中。

文档列出了文本字段(从Component继承)的焦点函数,但它在聚焦到输入字段方面没有做任何事情。

以下是文档中的示例代码

Ext.create('Ext.form.Panel', {
    title: 'Contact Info',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),        
    items: [{
        xtype: 'textfield',
        name: 'name',
        fieldLabel: 'Name',
        allowBlank: false 
    }, {
        xtype: 'textfield',
        id:'email',
        name: 'email',
        fieldLabel: 'Email Address',
        vtype: 'email'  
    }]
});

如果我致电Ext.getCmp('email').focus(),则无法看到任何可见的事情。

将一个字段集中在extjs 4中的正确方法是什么?

4 个答案:

答案 0 :(得分:5)

有时一个简单的解决方法是稍微推迟焦点调用,以防它与其他代码的时间问题,甚至是允许重点发生的UI线程。 E.g:

Ext.defer(function(){
    Ext.getCmp('email').focus();
}, 0);

答案 1 :(得分:2)

您的代码没有任何问题。我为它做了一个jsfiddle,它运行正常。你是否将代码包装在Ext.onReady()中?你还在使用什么浏览器?

答案 2 :(得分:2)

试试这个:

Ext.getCmp('email').focus(false, 20);

答案 3 :(得分:0)

而不是延迟解决问题,而是寻找获得焦点的内容。在父级上注意focusOnToFront属性。