Chapter 11: Using Menu-Based Controls--Defining menu structure and data

 

所有的基于菜单控件的data providers 都有如下特点来指定菜单的结构和内容:

 •data providers经常是有层次的,但是你也可以只有一层菜单。

 • 每一个菜单项中都包括了来决定这个菜单项的外观和行为的field,基于菜单的控件支持这些field:定义label text,icon,菜单项的type,和菜单项的status。

About menu data providers

 基于菜单控件的dataProvider属性具体指定了一个对象,这个对象定义了菜单的结构和内容。如果一个菜单的内容是动态的,你可以通过修改它的data Provider 来改变这个菜单显示内容,菜单控件通常是从具有一定层次的data provider中获得它需要的数据,比如从嵌套的对象数组中,或者一个XML对象。如果这个菜单展示了一个动态变化的数据,你使用实现了ICollectionView接口的对象,比如ArrayCollection 和 XMLListCollection.

菜单控件使用data descriptor来解析和使用data provider中的内容,默认情况下,菜单控件使用DefaultDataDescriptor类作为它的data descriptor,但是你可以创建一个你自己的类然后把它指定给Menu控件的dataDescriptor属性。

DefaultDataDescriptor类支持如下的数据类型:

XML A string that contains valid XML text, or any of the following objects containing valid E4X format XML data:
an <mx:XML> or <mx:XMLList> compile-time tag, or an XML or XMLList object.
Other objects An array of items, or an object that contains an array of items, where a node’s children are contained
in an item named children. You can also use the <mx:Model> compile-time tag to create nested objects that
support data binding, but you must follow the structure defined in “Using the <mx:Model> tag with Tree and
menu-based controls” on page 171.
Collections An object that implements the ICollectionView interface (such as the ArrayCollection or XMLList-
Collection classes) and whose data source conforms to the structure specified in either of the previous bullets. The
DefaultDataDescriptor class includes code to handle collections efficiently. Always use a collection as the data
provider if the data in the menu changes dynamically; otherwise, the Menu displays obsolete data.
For more information on hierarchical objects and data descriptors, including a detailed description of the formats
supported by the DefaultDataDescriptor, see “Data descriptors and hierarchical data structure” on page 168.
As with all data-driven controls, if the data provider contents can change dynamically, and you want the Menu to
update with the changes, ensure that the data source is a collection, such as an ArrayCollection or XMLListCol-
lection object. To modify the menu, change the underlying collection, and the menu will update its appearance
accordingly.
Node (menu item) tags in the XML data can have any name. Many examples in this topic use tags such as <node>
for all menu items, or <menuItem> for top-level items and <subMenuItem> for submenu items, but it might be
more realistic to use tag names that identify the data, such as <person>, <address>, and so on. The menu-
handling code reads through the XML and builds the display hierarchy based on the nested relationship of the
nodes. For more information, see “Specifying and using menu entry information” on page 349.
Most menus have multiple items at the top level, not a single root item. XML objects, such as the XML object
created by the <mx:XML> tag, must have a single root node. To display a menu that uses a data provider that has a
root that you do not want to display, set the Menu, PopUpMenuButton, or MenuBar showRoot property to false.

 

 指定和使用menu entry信息

       菜单控件的data provider中的信息决定了每一个menu entry 是怎样被显示和被使用的,为了能够访问或者改变菜单的内容,你修改data provider中的内容,基于菜单控件的类使用IMenuDataDescriptor中的接口来访问和控制那个定义了菜单行为和内容的data provider中的信息,Flex提供了DefaultDataDescriptor类实现了该接口,基于菜单的控件将会使用DefaultDataDescriptor类如果你没有设置dataDescriptor属性。

 

Menu entry types

每一个data provider的条目都能指定关于这个menu item的item 类型和特定的类型信息。基于菜单控件的类支持如下的item类型(指定type域的值如type:normal):
normal (the default) Selecting an item with the normal type triggers a change event, or, if the item has children,
opens a submenu.
check Selecting an item with the check type toggles the menu item’s toggled property between true and false
values. When the menu item is in the true state, it displays a check mark in the menu next to the item’s label.
radio Items with the radio type operate in groups, much like RadioButton controls; you can select only one
radio menu item in each group at a time. The example in this section defines three submenu items as radio buttons
within the group “one”.
When a radio button is selected, the radio item’s toggled property is set to true, and the toggled properties of
all other radio items in the group are set to false. The Menu control displays a solid circle next to the radio button
that is currently selected. The selection property of the radio group is set to the label of the selected menu item.
separator Items with the separator type provide a simple horizontal line that divides the items in a menu into
different visual groups.

 

Menu attributes
Menu items can specify several attributes that determine how the item is displayed and behaves. The following
table lists the attributes you can specify, their data types, their purposes, and how the data provider must represent
them if the menu uses the DefaultDataDescriptor class to parse the data provider:

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值