I have a list that uses a checkbox itemrenderer. The dataprovider is a collection of people. When I load the data from a file, each list item shows the person's name (last, first -- labelFunction), and the checkbox's selected property shows the person's included property. I.e.,
Smith, Doug - [x] Williams, Bob - [ ] Morris, Anne - [x]
However, each person also has an active property. I want to disable the checkbox for people who are inactive (meaning, "you can't include inactive people"). I have tried several methods to get this to work, including what's suggested here http://forums.adobe.com/thread/416786 to do the same thing in a datagrid. However, none of them work and all the checkboxes are enabled regardless of the person's active status. Here is my basic code:
<mx:List id="peopleIncludedList"
dataProvider="{someProvider}"
labelFunction="peopleLabelFunction">
<mx:itemRenderer>
<mx:Component>
开发者_StackOverflow <mx:CheckBox change="onChange(event)"
selected="{outerDocument.isIncluded(data)}">
<mx:Script>
<![CDATA[
private function onChange(e:Event):void
{
...
}
]]>
</mx:Script>
</mx:CheckBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
Any help on this would be greatly appreciated. Thank you.
-- Ian
I'll take a crack at it, but sometimes it is hard to tell without sample data.
First, don't reference the outerDocument in arenderer, and don't use binding, instead listen to the dataChange event
<mx:List id="peopleIncludedList"
dataProvider="{someProvider}"
labelFunction="peopleLabelFunction">
<mx:itemRenderer>
<mx:Component>
<mx:CheckBox change="onChange(event)" dataChange="onDataChange()">
<mx:Script>
<![CDATA[
private function onChange(e:Event):void
{
// not sure what this method is doing
}
private function onDataChange():void{
this.selected = isIncluded(data); // whatever your processing is
if(data.person.active == true){
this.enabled = true;
} else {
this.enabled = false;
}
}
]]>
</mx:Script>
</mx:CheckBox>
</mx:Component>
</mx:itemRenderer>
</mx:List>
Since stackoverflow only notifies me daily of new answers, I wasn't actively looking at this thread, and was more involved on the Adobe boards. Anyway, found a solution. Reference it here http://forums.adobe.com/message/3267367. Thanks everyone for your suggestions and helpfulness!
精彩评论