博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Using a CheckBox control as a list item renderer in Flex
阅读量:6207 次
发布时间:2019-06-21

本文共 3097 字,大约阅读时间需要 10 分钟。

The following example will show you how you can use a CheckBox control as a custom item renderer in a List control in Flex.

I haven’t done a lot of testing yet, so if you have any tips/suggestions/improvements, please, share them in the comments

<?
xml version="1.0" encoding="utf-8"
?>
<!--
 http://blog.flexexamples.com/2008/01/27/using-a-checkbox-control-as-a-list-item-renderer-in-flex/ 
-->
<
mx:Application 
xmlns:mx
="http://www.adobe.com/2006/mxml"
        xmlns:vo
="*"
        layout
="horizontal"
        verticalAlign
="middle"
        backgroundColor
="white"
        creationComplete
="init();"
>
    
<
mx:Script
>
        
<![CDATA[
            import mx.events.CollectionEvent;
            import mx.utils.ObjectUtil;
            private function init():void {
                arrColl.dispatchEvent(new CollectionEvent(CollectionEvent.COLLECTION_CHANGE));
            }
            private function arrColl_collectionChange(evt:CollectionEvent):void {
                try {
                    var tArr:Array = arrColl.source.filter(selectedOnly);
                    textArea.text = ObjectUtil.toString(tArr);
                    lbl.text = tArr.length.toString() + " item(s) selected";
                } catch (err:Error) {
                    // ignore.
                }
            }
            private function selectedOnly(item:ListItemValueObject, idx:uint, arr:Array):Boolean {
                return item.isSelected;
            }
        
]]>
    
</
mx:Script
>
    
<
mx:Array 
id
="arr"
>
        
<
vo:ListItemValueObject 
label
="One"
 isSelected
="true"
 
/>
        
<
vo:ListItemValueObject 
label
="Two"
 isSelected
="true"
 
/>
        
<
vo:ListItemValueObject 
label
="Three"
 isSelected
="true"
 
/>
        
<
vo:ListItemValueObject 
label
="Four"
 isSelected
="true"
 
/>
        
<
vo:ListItemValueObject 
label
="Five"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Six"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Seven"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Eight"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Nine"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Ten"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Eleven"
 isSelected
="false"
 
/>
        
<
vo:ListItemValueObject 
label
="Twelve"
 isSelected
="false"
 
/>
    
</
mx:Array
>
    
<
mx:ArrayCollection 
id
="arrColl"
            source
="{arr}"
            collectionChange
="arrColl_collectionChange(event);"
 
/>
    
<
mx:Panel 
id
="panel"
            title
="Items"
            status
="{arrColl.length} total"
            styleName
="opaquePanel"
>
        
<
mx:List 
id
="list"
                dataProvider
="{arrColl}"
                alternatingItemColors
="[#EEEEEE, white]"
                width
="150"
                rowCount
="8"
>
            
<
mx:itemRenderer
>
                
<
mx:Component
>
                    
<
mx:CheckBox 
selectedField
="isSelected"
                            change
="onChange(event);"
>
                        
<
mx:Script
>
                            
<![CDATA[
                                private function onChange(evt:Event):void {
                                    data.isSelected = !data.isSelected;
                                }
                            
]]>
                        
</
mx:Script
>
                    
</
mx:CheckBox
>
                
</
mx:Component
>
            
</
mx:itemRenderer
>
        
</
mx:List
>
        
<
mx:ControlBar 
horizontalAlign
="right"
>
            
<
mx:Label 
id
="lbl"
 
/>
        
</
mx:ControlBar
>
    
</
mx:Panel
>
    
<
mx:TextArea 
id
="textArea"
            verticalScrollPolicy
="on"
            width
="100%"
            height
="{panel.height}"
 
/>
</
mx:Application
>

View ListItemValueObject.as

package {
    public class ListItemValueObject {
        [Bindable]
        public var label:String;
        [Bindable]
        public var isSelected:Boolean;
        public function ListItemValueObject() {
            super();
        }
    }
}
    本文转自 OldHawk  博客园博客,原文链接:http://www.cnblogs.com/taobataoma/archive/2008/01/31/1059338.html
,如需转载请自行联系原作者
你可能感兴趣的文章
Whitelabel Error Page 专题
查看>>
Java Persistence/ManyToMany
查看>>
useradd使用方法
查看>>
SQL Server 2008性能故障排查(一)——概论
查看>>
HDOJ 1020 Encoding
查看>>
移除函数调用能有更好的性能
查看>>
墙内三大云数据库测试对比 不指定
查看>>
3.1、Android Studio在虚拟机中运行应用
查看>>
【Spring】Maven的安装
查看>>
【项目实战】---用户激活
查看>>
CDH集群安装&amp;测试总结
查看>>
突然发现有人翻译了Android开发的相关开发文档,而且翻译得很好,推荐下
查看>>
离开 YY 三年,赵斌和他的声网是如何做实时音视频互动的?
查看>>
我的Java开发学习之旅------&gt;计算从1到N中1的出现次数的效率优化问题
查看>>
背水一战 Windows 10 (51) - 控件(集合类): ItemsControl - 项模板选择器, 数据分组...
查看>>
防守式编程的艺术
查看>>
云计算深度学习平台架构与实践的必经之路
查看>>
数据可视化的7个好处
查看>>
2011云计算中国峰会倒计时
查看>>
走近“云地基”的开拓者云快线
查看>>