如何引用可编辑组合框的 TextInput?

发布于 2024-07-14 02:06:23 字数 307 浏览 4 评论 0原文

我有一个可编辑的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哽咽笑 2024-07-21 02:06:23

似乎没有必要因为这个原因引用 TextInput,因为默认情况下会选择文本。

It seems that referencing the TextInput for THIS reason is unnecessary, since the text is selected by default.

南城追梦 2024-07-21 02:06:23

我在使用 ComboBox 作为 DataGrid itemRenderer 时遇到了这个问题。 如果您需要引用 TextInput,您可以重写 ComboBox 并创建一个返回受保护的 textInput 的 getter。 就我而言,我需要防止组合框可编辑时发生的自动选择。 查看 ComboBox,这发生在 updateDisplayList 期间,因此这应该可以解决问题:

package com.whatever.controls
{

import mx.controls.ComboBox;

public class EditableComboBox extends ComboBox
{

    public function EditableComboBox()
    {
        super();
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        if (editable)
        {
            textInput.selectionBeginIndex   = text.length;
            textInput.selectionEndIndex     = text.length;
        }
    }

}
}

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:

package com.whatever.controls
{

import mx.controls.ComboBox;

public class EditableComboBox extends ComboBox
{

    public function EditableComboBox()
    {
        super();
    }

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
    {
        super.updateDisplayList(unscaledWidth, unscaledHeight);

        if (editable)
        {
            textInput.selectionBeginIndex   = text.length;
            textInput.selectionEndIndex     = text.length;
        }
    }

}
}
獨角戲 2024-07-21 02:06:23

在Combobox的“创建完成”事件中,您可以直接获取组件:

private function creationCompleteEvt ( evt:FlexEvent ) : void
{
    var targTextInput:UITextInput = UITextInput( myComboBox.getChildAt(2) );
    targTextInput.setSelection( 0, targTextInput.selectionEndIndex );
}

During the Combobox's "Creation Complete" event, you could get the component directly:

private function creationCompleteEvt ( evt:FlexEvent ) : void
{
    var targTextInput:UITextInput = UITextInput( myComboBox.getChildAt(2) );
    targTextInput.setSelection( 0, targTextInput.selectionEndIndex );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文