DateChooser

优质
小牛编辑
130浏览
2023-12-01

DateChooser控件用于显示月份名称,年份和每月日期的网格,其中列标记为星期几。

DateChooser控件允许用户选择日期,日期范围或多个日期。 该控件包含用于更改月份和年份的前进和后退箭头按钮。

Class 声明 (Class Declaration)

以下是mx.controls.DateChooser类的声明 -

public class DateChooser 
   extends UIComponent 
      implements IFocusManagerComponent, IFontContextComponent

公共属性 (Public Properties)

S.No财产和描述
1

allowDisjointSelection : Boolean

如果为true,则指定DateChooser控件中允许非连续(不相交)选择。

2

allowMultipleSelection : Boolean

如果为true,则指定DateChooser控件中允许多个选择。

3

dayNames : Array

DateChooser控件的工作日名称。

4

disabledDays : Array

一周内禁用的日子。

5

disabledRanges : Array

禁用单天和多天。

6

displayedMonth : int

与displayedYear属性一起使用,displayedMonth属性指定DateChooser控件中显示的月份。

7

displayedYear : int

与displayedMonth属性一起使用,displayedYear属性指定DateChooser控件中显示的年份。

8

firstDayOfWeek : Object

表示在DateChooser控件的第一列中显示的星期几的数字。

9

maxYear : int

去年可在控件中选择。

10

minYear : int

第一年可在控件中选择。

11

monthNames : Array

显示在DateChooser控件顶部的月份名称。

12

monthSymbol : String

此属性附加到monthNames属性指定的值的末尾,以定义DateChooser控件顶部显示的月份的名称。

13

selectableRange : Object

可选择日期的日期范围。

14

selectedDate : Date

在DateChooser控件中选择的日期。

15

selectedRanges : Array

选定的日期范围。

16

showToday : Boolean

如果为true,则指定今天在DateChooser控件中突出显示。

17

yearNavigationEnabled : Boolean

启用年度导航。

18

yearSymbol : String

此属性附加到DateChooser控件顶部显示的年末。

受保护的属性

S.No财产和描述
1

calendarLayoutStyleFilters : Object

[只读]从DateChooser传递到日历布局的样式集。

2

nextMonthStyleFilters : Object

[只读]从DateChooser传递到下个月按钮的样式集。

3

nextYearStyleFilters : Object

[只读]从DateChooser传递到下一年按钮的样式集。

4

prevMonthStyleFilters : Object

[只读]从DateChooser传递到上个月按钮的样式集。

5

prevYearStyleFilters : Object

[只读]从DateChooser传递到上一年按钮的样式集。

公共方法 (Public Methods)

S.No方法和描述
1

DateChooser()

构造函数。

事件 (Events)

S.No活动和描述
1

change

选择或更改日期时分派。

2

scroll

由于用户交互而导致月份更改时调度。

方法继承 (Methods Inherited)

该类继承以下类中的方法 -

  • mx.core.UIComponent
  • mx.core.FlexSprite
  • flash.display.Sprite
  • flash.display.DisplayObjectContainer
  • flash.display.InteractiveObject
  • flash.display.DisplayObject
  • flash.events.EventDispatcher
  • Object

Flex DateChooser控件示例

让我们按照以下步骤通过创建测试应用程序来检查Flex应用程序中DateChooser控件的用法 -

描述
1cn.xnip.client包下创建一个名为HelloWorld的项目,如Flex - Create Application一章中所述。
2修改HelloWorld.mxml ,如下所述。 保持其余文件不变。
3编译并运行应用程序以确保业务逻辑按照要求运行。

以下是修改后的mxml文件src/cn.xnip/HelloWorld.mxml

<?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"
   width = "100%" height = "100%" minWidth = "500" minHeight = "500"
   applicationComplete = "application_applicationCompleteHandler(event)">
   <fx:Style source = "/com/xnip/client/Style.css" />
   <fx:Script>
      <![CDATA[
         import mx.events.CalendarLayoutChangeEvent;
         import mx.events.FlexEvent;
         [Bindable]
         private var selectedDate:String = "";
         protected function dateChooser_changeHandler
            event:CalendarLayoutChangeEvent):void {            
            var date:Date = DateChooser(event.target).selectedDate;
            selectedDate = dateFormatter.format(date);
         }
         protected function application_applicationCompleteHandler
            (event:FlexEvent):void {
            selectedDate = dateFormatter.format(new Date());
         }
      ]]>
   </fx:Script>
   <s:BorderContainer width = "550" height = "400" id = "mainContainer" 
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50" 
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Form Controls Demonstration" 
            fontSize = "40" color = "0x777777" styleName = "heading" />
         <s:Panel id = "dateChooserPanel" title = "Using DateChooser" width = "400" 
            height = "300" includeInLayout = "true" visible = "true">
            <s:layout>
               <s:HorizontalLayout  gap = "10" verticalAlign = "middle" 
                  horizontalAlign = "center" />	
            </s:layout>
            <mx:DateChooser id = "dateChooser" yearNavigationEnabled = "true"
               change = "dateChooser_changeHandler(event)" />
            <s:Label id = "selection" fontWeight = "bold" 
               text = "Date selected: {selectedDate}" />
         </s:Panel>			
      </s:VGroup>	 
   </s:BorderContainer>	
</s:Application>

一旦准备好完成所有更改,让我们像在Flex - Create Application章节中那样在正常模式下编译和运行应用程序

Flex DateChooser控件