javascript - 无法为 Extjs 文本字段设置焦点

标签 javascript extjs extjs4.2

我是 Extjs 的新手。我有字段的形式。我需要为特定领域设置重点。这是我正在使用的代码。

var priceTFLme = {
    xtype: 'numberfield',
    id:'priceLme',
    fieldLabel: 'Price',
    name: 'price',
    value: bidOffer,
    minValue: 0,
    maxValue: 100,
    allowDecimals: true,
    decimalPrecision: 3,
    step: 0.005,
    vtype: 'natural'
};

var quantityTFLme = {
    xtype: 'textfield',
    id: 'quantityLme',
    fieldLabel: 'Quantity',
    value: '',
    editable: true,
    hasFocus: true,
    vtype: 'natural',
    listeners: {
        afterrender: function(field) {
            field.focus(false, 1000);
        }
    }
};

var formLME =  new Ext.FormPanel({
    labelWidth:  85,
    frame:true,
    id:'lmeHeaders',
    bodyStyle:'padding:10px 10px 0',
    defaults: {width: 225},
    defaultType: 'textfield',

    items: [quantityTFLme, priceTFLme ],

    buttons: [{
        id:'buyIdLME',
        handler: function () {

        }
    }, {
        id:'sellIdLME',
        handler: function () {

        }
    }]
});

var winLme = Ext.widget('window', {
    closeAction: 'close',
    layout: 'fit',
    resizable: false,
    constrain: true,
    modal: true,
    items: formLME  
});

function requestForLMEPrice() {
    if (!winLme.rendered) {
        winLme.render(Ext.getBody());
    }
    winLme.center();
    winLme.show();
} 

我要关注的领域有数量。但是我无法集中注意力。

有人可以帮忙吗?

此外,我尝试使用 Ext.getCmp('quantityTFLme').focus(false, 200);

最佳答案

尝试 defer在触发焦点之前,

示例代码:

afterrender: function(field) {
   Ext.defer(function() {
       field.focus(true, 100);
   }, 1);
}

关于javascript - 无法为 Extjs 文本字段设置焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22803204/

相关文章:

javascript - 向所有 AngularJS Controller 添加方法

javascript - 使用 Rangy 将键盘插入符号移动到元素的末尾

php - 如何在没有 window.open 的情况下从 Javascript 启动 PHP 文件

javascript - ExtJs 4.2 - 取消/清除组件的动画链

javascript - ExtJS:使用 gridpanel 过滤器标题忽略/重置我添加的商店过滤器

javascript - 如何在 pagingtoolbar Ext js 4.2 中获取检查的行数?

javascript - 如何显示过滤后的 ng-repeat 数据的长度

javascript - 从混合字符串/JSON 数据中提取特定变量

extjs - 将图表导出为 PDF 以进行打印 EXT JS 4

javascript - 在javascript问题中解析日期