现在的位置: 首页 > 综合 > 正文

flex日期,数字和货币的简单格式化操作

2013年01月31日 ⁄ 综合 ⁄ 共 1489字 ⁄ 字号 评论关闭
经常会用的总结下

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" 
			   minWidth="955" minHeight="600">
	<!-- 用于布局,简单垂直布局-->
	<s:layout>
		<s:VerticalLayout/>
	</s:layout>
	
	<fx:Declarations>
		<!-- 将非可视元素(例如服务、值对象)放在此处 -->
		<!--设置日期显示格式  用到DateTimeFormatter标签和dateTimepattern属性(y小写,M大写,d小写)-->
		<s:DateTimeFormatter id="dtf" dateTimePattern="yyyy-MM-dd"/>
		
		<!-- 下面设置数字格式,用到NumberFormatter标签,decimalSeparator是小数点,
		groupingSeparator是整数分组的标点,useGrouping="true"使用分组,fractionalDigits每3个数分一组
		-->
		<s:NumberFormatter id="myNumberFormatter" decimalSeparator="." 
						   groupingSeparator="," useGrouping="true" fractionalDigits="3" 
						   errorText="{myText3.text} is NaN"/>
		
		<!--useCurrencySymbol使用货币符号,currencySymbol货币符号 -->
		<s:CurrencyFormatter id="myCurrencyFormatter" decimalSeparator="." 
							 groupingSeparator="," useCurrencySymbol="true" 
							 useGrouping="true" currencySymbol="¥"/>
	</fx:Declarations>
	<!-- 下面是简单测试-->
	<mx:DateChooser id="myDateChooser"/><!-- 展开的日期选择-->
	<mx:DateField id="myDateField"/><!-- 点击后展开的日期-->
	
	<mx:TextInput id="myText1" width="200" 
				  text="{dtf.format(myDateChooser.selectedDate)}"/>
	<mx:TextInput id="myText2" width="200" 
				  text="{dtf.format(myDateField.selectedDate)}"/>
	
	<mx:TextInput id="myText3" width="200" text=""/>
	<mx:TextInput id="myText4" width="200" 
				  text="{myNumberFormatter.format(myText3.text)}"/>
	
	<mx:TextInput id="myText5" width="200" text=""/>
	<mx:TextInput id="myText6" width="200" 
				  text="{myCurrencyFormatter.format(myText5.text)}"/>
</s:Application>

抱歉!评论已关闭.