0

我有一个包含两列的数据网格。数据类型和值。数据类型有一个组合框,其中包含 char、int、unsigned int、signed int 等选项。现在我想验证在 value 列中输入的值。我正在使用以下方法。

<mx:DataGridColumn headerText="Value"
                               dataField="Values"
                               width="100"
                               editable="{!this.areVariablesReadOnly}">
            <mx:itemEditor> <mx:Component> <mx:TextInput restrict="0-9" maxChars="3" /> </mx:Component> </mx:itemEditor>
            </mx:DataGridColumn>

这仅针对 int 值验证 value 列的字段。现在,如果选择了 char,我需要使用不同的 itemEditor 以不同的方式进行验证。简而言之,

   if (int)
          use ItemEditor1 
   else if (char)
      use ItemEditor2
   else if (condition)
      use Itemeditor3.

有人能指出我正确的方向吗?

4

1 回答 1

0

data物业(以及 dataChange活动)将使您的生活更轻松。

例如,
(假设您的 Datatype 字段是type

在您的 MXML 中:

<mx:itemEditor>
    <fx:Component>
        <local:ValueInput type="{data.type}"/>
    </fx:Component>
</mx:itemEditor>

值输入.as:

package
{
    import mx.controls.TextInput;

    public class ValueInput extends TextInput
    {
        public function set type(value:String):void
        {
            switch (value)
            {
                case "char":
                    restrict = null;
                    break;
                case "int":
                    restrict = "0-9";
                    break;
                case "hex":
                    restrict = "0-9A-F";
                    break;
            }
        }
    }
}

但是,我不能说这是“正确的方向”。这只是一种方法。可以有许多其他的创造性方式,这也取决于开发人员的编码风格。

你试图做的也是一个好方法。MX 组件的实现只需要更长的时间。

希望这可以帮助。

于 2014-04-23T05:40:10.887 回答