如何引用可编辑组合框的 TextInput?
我有一个可编辑的 ComboBox 组件,我想引用显示的 TextInput,以便以编程方式选择其中的文本。 这在 TextInput 上非常简单:
private function selectNameText():void
{
nameTextInput.selectionBeginIndex = 0;
nameTextInput.selectionEndIndex = nameTextInput.text.length;
}
但我找不到任何方法来访问可编辑 ComboBox 的 TextInput。
I have an editable ComboBox component and I want to reference the TextInput that is shown, in order to programmatically select the Text in it. This is very straightforward on a TextInput:
private function selectNameText():void
{
nameTextInput.selectionBeginIndex = 0;
nameTextInput.selectionEndIndex = nameTextInput.text.length;
}
But I can't find any way to access the TextInput of an editable ComboBox.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎没有必要因为这个原因引用 TextInput,因为默认情况下会选择文本。
It seems that referencing the TextInput for THIS reason is unnecessary, since the text is selected by default.
我在使用 ComboBox 作为 DataGrid itemRenderer 时遇到了这个问题。 如果您需要引用 TextInput,您可以重写 ComboBox 并创建一个返回受保护的 textInput 的 getter。 就我而言,我需要防止组合框可编辑时发生的自动选择。 查看 ComboBox,这发生在 updateDisplayList 期间,因此这应该可以解决问题:
I ran into this problem when using a ComboBox as a DataGrid itemRenderer. If you need to reference the TextInput you can override ComboBox and create a getter that returns the protected textInput. In my case I needed to prevent the auto-selection that occurs when a ComboBox is editable. Looking at ComboBox, this occurs during updateDisplayList so this should do the trick:
在Combobox的“创建完成”事件中,您可以直接获取组件:
During the Combobox's "Creation Complete" event, you could get the component directly: