热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Flex3:自定义项呈示器不侦听父级调度的事件-Flex3:CustomItemRendererdoesnotlistentoeventsdispatchedbyparent

IhaveaListwithacustomItemRenderer.TheItemRenderercontainsaCheckboxandaLabel.Thecomp

I have a List with a custom ItemRenderer. The ItemRenderer contains a Checkbox and a Label. The component with the List has a 'select all' checkbox. When the 'select all' checkbox is checked, it dispatches an event that each item should listen to in order to select its own checkbox. The eventlistener is added on creationComplete of each item, and the event is dispatched correctly when the 'select all' checkbox is selected, but the listener in the custom ItemRenderer does not listen.

我有一个带有自定义ItemRenderer的List。 ItemRenderer包含一个复选框和一个Label。具有List的组件具有“全选”复选框。选中“全选”复选框后,它会调度每个项目应监听的事件,以便选择自己的复选框。 eventlistener将添加到每个项目的creationComplete上,并且在选中“全选”复选框时会正确调度该事件,但自定义ItemRenderer中的侦听器不会侦听。

How do I make the ItemRenderer listen to an event that is dispatched in its parent??

如何让ItemRenderer监听在其父级中调度的事件?

I'll add some code examples to clarify:

我将添加一些代码示例来澄清:

------- container ----------

   
      
   
   
   



------- renderer ----------


   
      
   

   
   

Please note that the users ArrayCollection or its containing user objects cannot be changed because I need the values later on. So when 'selectAll' is clicked, each checkbox in the list should also be checked.

请注意,用户ArrayCollection或其包含的用户对象无法更改,因为我稍后需要这些值。因此,当单击“selectAll”时,还应检查列表中的每个复选框。

4 个解决方案

#1


Your custom ItemRenderers should not register an event listener with their parent, but with your "select all" checkbox, i.e.

您的自定义ItemRenderers不应该向其父级注册事件监听器,而是使用“全选”复选框,即

theCheckbox.addEventListener(YourEvent.YOUR_EVENT, itemRendererSelectAllHandler);

Failing that, can you post your code which adds the event listener and which dispatches the event form the checkbox?

如果不这样做,您可以发布添加事件监听器的代码,并从复选框调度事件吗?

edit:

Here's your bug: In renderer's init(), you need to add an event listener not to the renderer, but to the container which dispatches the event. So make that a

这是您的错误:在渲染器的init()中,您需要将事件侦听器添加到渲染器,而不是添加到调度事件的容器。所以,做一个

container.addEventListener(Container.SELECT_ALL_USERS, selectAllHandler, false, 0, true);

#2


Doing select all in flex is little complex but I will tell you the way we did it and it works great.

在flex中选择all并不复杂,但我会告诉你我们做的方式并且效果很好。

We created a List derived control called "ExList" which has a property "selectAllCB" which we bind it to existing check box which will work for select all logic. Please note, when we set selectAllCB property, we make ExList to listen to checkbox's events.

我们创建了一个名为“ExList”的List派生控件,它有一个属性“selectAllCB”,我们将它绑定到现有的复选框,该复选框适用于select all逻辑。请注意,当我们设置selectAllCB属性时,我们使ExList监听复选框的事件。

When checkbox is checked, we manually set selectedItems array to array of dataProvider and all items are selected.

选中复选框后,我们手动将selectedItems数组设置为dataProvider数组,并选择所有项目。

Playing with itemRenderer doesnt work correctly because when you program your list again and again everytime you have to write so much of code.

使用itemRenderer无法正常工作,因为每当您必须编写大量代码时,一次又一次地对列表进行编程。

I am attaching some sample code here below..

    public class ExList extends List 
    {
        public function ExTileList()
        {
            super();
            this.allowMultipleSelection = true;
        }

        private var _selectAllCB:CheckBox = null;
        [Bindable]
        public function get selectAllCB():CheckBox
        {
            return _selectAllCB;
        }
        public function set selectAllCB(v:CheckBox):void
        {
            if(v==null)
                return;
            _selectAllCB = v;
            v.addEventListener(ListEvent.ITEM_CLICK, handleAllChange,false, 0 , true);
            v.addEventListener("change", handleAllChange,false, 0 , true);
        }

        private function handleAllChange(e:Event):void
        {
            if(_selectAllCB.selected)
            {
                this.selectedItems = this.dataProvider.toArray();
            }
            else
            {
                this.selectedItems = new Array();
            }
        }
}

And you can use it as...

你可以用它......




// Please note its in curly braces

#3


This is how I achieved the solution:

这就是我实现解决方案的方式:

    

    
 
 
 
  
   
    
    
   
  
 
 
  
  
 

#4


The simple solution is to use typed objects in the list of data you are presenting and then take advantage of databinding and the binding utils to capture changes to the underlying data property on the item renderer. Override the 'set data' function in the item renderer to do whatever you need when some property in the object gets changed to reflect the 'select all/de select all' state.

简单的解决方案是在您呈现的数据列表中使用类型化对象,然后利用数据绑定和绑定工具来捕获对项呈示器的基础数据属性的更改。覆盖项呈示器中的“设置数据”功能,以便在对象中的某些属性发生更改以反映“全选/全选”状态时执行所需操作。


推荐阅读
  • 在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板
    本文介绍了在Xamarin XAML语言中如何在页面级别构建ControlTemplate控件模板的方法和步骤,包括将ResourceDictionary添加到页面中以及在ResourceDictionary中实现模板的构建。通过本文的阅读,读者可以了解到在Xamarin XAML语言中构建控件模板的具体操作步骤和语法形式。 ... [详细]
  • 本文介绍了使用kotlin实现动画效果的方法,包括上下移动、放大缩小、旋转等功能。通过代码示例演示了如何使用ObjectAnimator和AnimatorSet来实现动画效果,并提供了实现抖动效果的代码。同时还介绍了如何使用translationY和translationX来实现上下和左右移动的效果。最后还提供了一个anim_small.xml文件的代码示例,可以用来实现放大缩小的效果。 ... [详细]
  • android listview OnItemClickListener失效原因
    最近在做listview时发现OnItemClickListener失效的问题,经过查找发现是因为button的原因。不仅listitem中存在button会影响OnItemClickListener事件的失效,还会导致单击后listview每个item的背景改变,使得item中的所有有关焦点的事件都失效。本文给出了一个范例来说明这种情况,并提供了解决方法。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • Android系统移植与调试之如何修改Android设备状态条上音量加减键在横竖屏切换的时候的显示于隐藏
    本文介绍了如何修改Android设备状态条上音量加减键在横竖屏切换时的显示与隐藏。通过修改系统文件system_bar.xml实现了该功能,并分享了解决思路和经验。 ... [详细]
  • Android开发实现的计时器功能示例
    本文分享了Android开发实现的计时器功能示例,包括效果图、布局和按钮的使用。通过使用Chronometer控件,可以实现计时器功能。该示例适用于Android平台,供开发者参考。 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • SpringMVC接收请求参数的方式总结
    本文总结了在SpringMVC开发中处理控制器参数的各种方式,包括处理使用@RequestParam注解的参数、MultipartFile类型参数和Simple类型参数的RequestParamMethodArgumentResolver,处理@RequestBody注解的参数的RequestResponseBodyMethodProcessor,以及PathVariableMapMethodArgumentResol等子类。 ... [详细]
  • JS实现一键分享功能
    本文介绍了如何使用JS实现一键分享功能,并提供了2019独角兽企业招聘Python工程师的标准。同时,给出了分享到QQ空间、新浪微博和人人网的链接。 ... [详细]
  • Activiti7流程定义开发笔记
    本文介绍了Activiti7流程定义的开发笔记,包括流程定义的概念、使用activiti-explorer和activiti-eclipse-designer进行建模的方式,以及生成流程图的方法。还介绍了流程定义部署的概念和步骤,包括将bpmn和png文件添加部署到activiti数据库中的方法,以及使用ZIP包进行部署的方式。同时还提到了activiti.cfg.xml文件的作用。 ... [详细]
  • 进入配置文件目录:[rootlinuxidcresin-4.0.]#cdusrlocalresinconf查看都有哪些配置文件:[rootlinuxid ... [详细]
  • linux下编译安装lnmp
    2019独角兽企业重金招聘Python工程师标准#######################安装依赖#####################安装必要的包:y ... [详细]
  • 在使用豆瓣OAuth登录接口时,我们需要发送这样的HTTPREQUEST请求:GETv2user~meHTTP1.1Host:https:api.douban.com ... [详细]
author-avatar
傻傻的笑没心没肺wy
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有