免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2506 | 回复: 0
打印 上一主题 下一主题

flex4_DropDownList控件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-12-21 08:44 |只看该作者 |倒序浏览
1.DropDownList控件简介
    该控件主要用于“竖向显示单列表数据项”。如果数据项过多,可以出现一个垂直滚动条。

继承关系如下:
    DropDownList Inheritance DropDownListBase Inheritance List Inheritance ListBase Inheritance SkinnableDataContainer Inheritance SkinnableContainerBase Inheritance SkinnableComponent Inheritance UIComponent

子类:
    FileSystemList, Menu, Tree

2.List属性与事件
    名称               描述
editable            数据是否可编辑,值为"false|true"
editedItemPosition  item renderer的位置,默认值为"No default"
editorDataField     "text"
editorHeightOffset="0"
editorUsesEnterKey="false|true"
editorWidthOffset="0"
editorXOffset="0"
editorYOffset="0"
imeMode="null"   
itemEditor="TextInput"
itemEditorInstance="Current item editor"
rendererIsEditor="false|true"


3.属性DataProvider,LabelFunction--ArrayCollection数据源绑定并自定显示信息
功能说明:
    绑定ArrayCollection类型数据源,并自定义控件上的显示信息

代码:
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

[Bindable]   
public var roleList:ArrayCollection
       = new ArrayCollection([
         {label:"good",data:"isgood"},
         {label:"bad",data:"isbad"}
       ]);
private function lst_exam_getDispName(item:Object):String {
       var result:String = "";  
       if(item.hasOwnProperty("label")){  
             result+= item.label+ ",";  
       }  
       if(item.hasOwnProperty("data")){  
             result+= item.data;  
       }  
       return result;
}
]]>
</fx:Script>
<mx:List  id="lst_exam"
       width="30%"
       dataProvider="{roleList}"
       labelFunction="lst_exam_getDispName"
      />
注:
    1.如果要显示的信息直接是数据源中的一个属性的值,可使用下面代码指定
            labelField="label"
      labelField:指明显示roleList对象中的哪个属性,默认值是"label"


4.属性dataTipFunction--显示文字提示
功能说明:
    鼠标指向每一个数据项,显示提示信息

    dataTipFunction和showDataTips为父类ListBase的属性,具体参考《FLEX控件_ListBase》

代码:
<fx:Script>
<![CDATA[
    //数据源参考上例
    private function myDataTipFunction(value:Object):String  { 
          return (value.label + "::" + value.data); 
    } 
]]>
</fx:Script>
<mx:List  id="lst_exam"
       width="30%"
       dataProvider="{roleList}"
       labelField="label"
       showDataTips="true"
       dataTipFunction="myDataTipFunction"/>
注:
    1.如果每一个数据项的提示信息恰好是另一个属性的值,则直接使用下面代码指定即可   
                dataTipField="data" //data表示roleList中的一个属性
    2. mx:linkBar和mx:ButtonBar由于没有继承ListBase,因此不能使用这个方法,本人也没有找到具体方法实现本功能
    3.用List控件最大的问题在于,数据之间没有直线作间隔,不如LinkBar好看,这个问题待解决

5.属性wordWrap--如果文字过长,允许换行
功能说明:
    如果显示的数据项的文字过长,控件默认为多余的文字不显示,本功能指定控件将过长的数据项换行显示

代码:
<fx:Script>
<![CDATA[
    //数据源参考上例
]]>
</fx:Script>
<mx:List  id="lst_exam"
       dataProvider="{roleList}"
       labelField="label"
       width="220"
       height="200"
       variableRowHeight="true"
       wordWrap="true"
/>
注:
    1.利用wordWrap和variableRowHeight属性,指定过长的数据项自动换行

6.属性alternatingItemColors--指定控件的交互底色
功能说明:
    自定义控件的交互底色
代码:
    <mx:List alternatingItemColors="[#66FFFF, #33CCCC]".../ >


7.事件itemClick--显示选中数据项的所有属性
 功能说明:
    先与数据源ArrayCollection绑定,当点击控件中的一个数据项时,显示该数据项的所有属性

代码:
<fx:Script>
<![CDATA[
    //数据源参考上例
    protected function lst_exam_itemClickHandler(event:ListEvent):void
    {
        var t:List=event.currentTarget as List;
        Alert.show(t.selectedItem.label+"::"+t.selectedItem.data);
    }
]]>
</fx:Script>
<mx:List  id="lst_exam"
       width="30%"
       dataProvider="{roleList}"
       labelField="label"
       itemClick="lst_exam_itemClickHandler(event)"/>





参考文献:
1.List control. http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/mx/controls/List.html
2.Add ToolTip in List/ComboBox Control. http://fhuan123.javaeye.com/blog/359029
3.http://help.adobe.com/en_US/flex/using/WSc2368ca491e3ff92-59bf082612135c9e688-7fff.html
4.http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/components/DropDownList.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP