Flex 4 s:List itemRenderer labels not displayed
I have the following s:List
<s:List
id="lstOther"
borderVisible="false"
width="100%" height="100%"
dataProvider="{this.handler.itemRendererType}"
labelFunction="labelFunction"
itemRendererFunction="itemRendererFunction">
</s:List>
The functions for itemRendererFunction and labelFunction look like this:
private function itemRendererFunction(item:Object):IFactory {
var clazz:Class = DefaultItemRenderer;
switch(item.data) {
case "Security Unit":
clazz = CheckBox;
break;
default:
clazz = CheckBoxEditLabel;
}
return new ClassFactory(clazz);
}
private function labelFunction(item:Object):String {
return "testing";
}
My data provider (dataProv开发者_C百科ider="{this.handler.itemRendererType}") is composed as follows:
public var itemRendererType:ArrayCollection = new ArrayCollection([
{name:"otherLabel1", data:"Security Unit"},
{name:"otherLabel2", data:"Test 1"},
{name:"otherLabel3", data:"Test 2"}
]);
I first tried setting labelField in the s:List to 'name'. Nothing showed up in the list control. As can be seen above, I tried using a label function and returning a hard coded value ("testing"). Still nothing shows up.
Why is the text for the labels not showing up?
Any help would be greatly appreciated. Thanks!
My immediate guess is that this.handler
is null; you should debug to see why that is (what is handler anyways?). You were right about using labelField="name", that should work, but won't show anything if you don't have any data. Also, I'm fairly sure your itemRendererFunction isn't going to work properly since it needs to return a component that extends s:ItemRenderer.
this.handler is not null. handler is the actionscript class where the itemRendererType is defined.
The following item renderer works fine with your sample:
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
autoDrawBackground="true">
<s:CheckBox label="{label}" />
</s:ItemRenderer>
精彩评论