ExtJS 文档描述了 textfields
的方法 focus
,该方法将聚焦文本字段或返回 false:https://docs.sencha.com/extjs/6.7.0/modern/Ext.field.Text.html#method-focus
通常这似乎工作得很好,但是一旦应该聚焦的文本字段位于list
(listitem
的一部分)内,焦点就会立即被删除并设置到父 listitem
容器。然而 Focus 返回 true(焦点实际上在该字段上持续了几毫秒)。
https://fiddle.sencha.com/#view/editor&fiddle/315h通过示例展示了这一点。第一个按钮尝试将焦点集中在列表内的第一个文本字段(失败),第二个按钮将焦点集中在列表
下方的字段。
有什么方法可以防止 listitem
获得焦点吗?
fiddle 代码:
Ext.application({
name: 'Fiddle',
launch: function () {
Ext.create({
fullscreen: true,
xtype: 'container',
items: [{
xtype: 'list',
itemConfig: {
xtype: 'container',
items: [{
xtype: 'component',
html: 'Row'
}, {
xtype: 'textfield',
value: 'Focus Me'
}],
margin: '15px 0'
},
data: [{
title: 'Item 1'
}, {
title: 'Item 2'
}, {
title: 'Item 3'
}, {
title: 'Item 4'
}]
}, {
xtype: 'button',
text: 'Try to focus',
handler: function () {
this.up('container').down('list').down('textfield').focus();
Ext.toast(this.up('container').down('list').down('textfield').hasFocus + '');
}
}, {
xtype: 'textfield',
itemId: 'focusable',
value: 'Focusable'
}, {
xtype: 'button',
text: 'Try to focus',
handler: function () {
this.up('container').down('#focusable').focus();
Ext.toast(this.up('container').down('#focusable').hasFocus + '');
}
}]
});
}
});
在 ExtJS 6.7 上,第一次单击列表中的文本字段甚至不起作用,但这似乎在 7.0 中得到了修复。
最佳答案
设置defaultFocus对于 listitem
容器。它对我有用(fiddle)。
附注谢谢你的 fiddle 例子。很少有人这样做。
关于javascript - 将文本字段聚焦在列表内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58838822/