【问题标题】:How can I reference the TextInput of an editable ComboBox?如何引用可编辑 ComboBox 的 TextInput?
【发布时间】:2009-03-03 19:49:25
【问题描述】:

我有一个可编辑的 ComboBox 组件,我想引用显示的 TextInput,以便以编程方式选择其中的文本。这在 TextInput 上非常简单:

private function selectNameText():void
{
    nameTextInput.selectionBeginIndex = 0;

    nameTextInput.selectionEndIndex = nameTextInput.text.length;
}

但我找不到任何方法来访问可编辑 ComboBox 的 TextInput。

【问题讨论】:

    标签: apache-flex actionscript combobox editor textinput


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我在使用 ComboBox 作为 DataGrid itemRenderer 时遇到了这个问题。如果您需要引用 TextInput,您可以覆盖 ComboBox 并创建一个返回受保护的 textInput 的 getter。在我的情况下,我需要防止 ComboBox 可编辑时发生的自动选择。查看 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;
              }
          }
      
      }
      }
      

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 2010-10-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-04-04
          • 2010-09-10
          • 1970-01-01
          • 2012-03-08
          相关资源
          最近更新 更多