Jun 25
很多时候我们都需要为星期一是第0天还是第1天而烦恼,接下来一点常用的小技巧演示了Flex中如何利用ActionScript封装类,对一周的日期名称进行封装(DateFormatter中),从而让我们无需关注是第0天还是第1天的问题。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="middle" backgroundColor="white">
- <mx:Script>
- <![CDATA[
- private function doLabel(item:Date):String {
- return dateFormatter.format(item);
- }
- ]]>
- </mx:Script>
- <mx:DateFormatter id="dateFormatter" formatString="MMM D, YYYY"/>
- <mx:DateField todayColor="red" labelFunction="doLabel" firstDayOfWeek="{Days.MONDAY}" />
- </mx:Application>
下面是ActionScript封装类的代码:
- // ActionScript file
- package {
- public class Days {
- public static const SUNDAY:uint = 0;
- public static const MONDAY:uint = 1;
- public static const TUESDAY:uint = 2;
- public static const WEDNESDAY:uint = 3;
- public static const THURSDAY:uint = 4;
- public static const FRIDAY:uint = 5;
- public static const SATURDAY:uint = 6;
- }
- }
代码:Peter deHaan 翻译/整理/编译:minidxer
