使用 itemEditor 在 flex 数据网格中进行验证 [英] validation in flex datagrid using itemEditor
问题描述
我有一个包含两列的数据网格.数据类型和值.数据类型有一个组合框,其中包含 char、int、unsigned int、signed int 等选项.现在我想验证值列中输入的值.我正在使用以下方法.
I have a datagrid which conatains two columns. Datatype and value. Datatype has a combobox with options like char, int, unsigned int, signed int etc.Now i want to have validation on what value is entered in value column. I am using following method .
<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 值验证值列的字段.现在,如果选择了字符,我需要使用不同的 itemEditor 以不同的方式进行验证.总之,
This validates value column's fields only for int values. Now if char is selected , i need to use different itemEditor to validate in a different way. In short,
if (int)
use ItemEditor1
else if (char)
use ItemEditor2
else if (condition)
use Itemeditor3.
有人能指出我正确的方向吗?
Can anybody point me in correct direction?
推荐答案
data
属性(以及 dataChange
事件)将使您的生活更轻松.
The data
property (and also dataChange
event) will make your life easier.
例如,
(假设您的 Datatype 字段是 type
)
在您的 MXML 中:
In your MXML:
<mx:itemEditor>
<fx:Component>
<local:ValueInput type="{data.type}"/>
</fx:Component>
</mx:itemEditor>
ValueInput.as:
ValueInput.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;
}
}
}
}
<小时>
但是,我不能说这是正确的方向".这只是一种方法.可以有很多其他的创意方式,也取决于开发者的编码风格.
However, I can't say this is the "correct direction". It is just one way of doing it. There can be many other creative ways, and it also depends on developer's coding style.
你尝试做的也是一个很好的方法.只是为 MX 组件实现需要更长的时间.
What you were trying to do was also a fine way. It just takes a bit longer to implement for MX components.
希望这会有所帮助.
这篇关于使用 itemEditor 在 flex 数据网格中进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!