Complex Editor

Complex Editor

Now suppose you want to do something a little more complex that doesn't have a ready-made Flex control available. Here is one which allows a credit card number to be entered using 4 separate 4-digit fields:

	<mx:DataGrid x="46" y="463" editable="true" dataProvider="{accountDB}" width="302">
		<mx:columns>
			<mx:DataGridColumn headerText="Account" dataField="account" width="100"/>
			<mx:DataGridColumn headerText="Credit Card" dataField="ccard" editorDataField="value">
				<mx:itemEditor>
					<mx:Component>
						<mx:HBox>
							<mx:Script>
							<![CDATA[
								public function get value() : String
								{
									return part1.text+part2.text+part3.text+part4.text;
								}
								override public function set data(value:Object):void
								{
									super.data = value;
									part1.text = value.ccard.substr(0,4);
									part2.text = value.ccard.substr(4,4);
									part3.text = value.ccard.substr(8,4);
									part4.text = value.ccard.substr(12,4);
								}
							]]>
							</mx:Script>
							<mx:TextInput id="part1" maxChars="4" restrict="[0-9]" width="40" />
							<mx:TextInput id="part2" maxChars="4" restrict="[0-9]" width="40" />
							<mx:TextInput id="part3" maxChars="4" restrict="[0-9]" width="40" />
							<mx:TextInput id="part4" maxChars="4" restrict="[0-9]" width="40" />
						</mx:HBox>
					</mx:Component>
				</mx:itemEditor>
			</mx:DataGridColumn>
		</mx:columns>
	</mx:DataGrid>

This inline itemEditor follows the same rules as other itemEditors and names the editorDataField as "value". The component chosen for the itemEditor is the HBox - which does not have a "value" property. To make this itemEditor work, a getter function named value is created to return the concatenation of the 4 input fields. Now when editing for the cell completes, the DataGrid can call upon the value property of the itemEditor and it will receive the combined fields.

You can also see that I have overridden the data setter function. In that function I split up the credit card number among the four TextInput fields. This is the technique you use to display the data to be edited. The editorDataField is the property used to retrieve the new value.


原文:http://weblogs.macromedia.com/pent/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值