作者:傻傻的笑没心没肺wy | 来源:互联网 | 2023-05-18 12:07
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 个解决方案
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