为刚创建的窗口中的文本输入设置焦点 [英] Set focus for text input in just created window
问题描述
我有微不足道的窗口:
this.window = Ext.widget('window', {
title: 'Find',
closeAction: 'hide',
width: 300,
layout: 'fit',
items: form
});
其中有琐碎的形式
var form = Ext.widget('form', {
layout: {
type: 'vbox',
align: 'stretch'
},
border: false,
bodyPadding: 10,
items: [
this.findInput,
]
});
只有一项
this.findInput = Ext.widget('textfield', {
name: 'find'
});
问题是:如何在显示窗口后立即设置焦点?我试图在几乎所有没有成功的窗口事件处理程序中调用this.findInput
的.focus()
方法.
The issue is: how to set focus right after window is shown? I tried to call .focus()
method of this.findInput
in almost every window event handler with no luck.
在DOM完全创建所有元素之前,似乎同时调用了afterrender
.
Seems like even afterrender
is called synchronously before DOM has created all the elements completely.
我错过了什么?我应该绑定什么事件以呈现所有元素并能够接受焦点?
What have I missed? What event should I bind to to have all the elements rendered and able to accept the focus?
PS:如果我在10毫秒之类的小间隔后调用相同的.focus()
-我得到了重点,但这不是解决方案
PS: if I call the same .focus()
after small interval like 10ms - I get it focused, but it's not a solution
推荐答案
签出activeItem
属性-,或者您也可以使用defaultFocus
: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.Window-cfg-defaultFocus
or you can also use defaultFocus
: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.window.Window-cfg-defaultFocus
这篇关于为刚创建的窗口中的文本输入设置焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!