I'm dynamically creating an IList to use as a dataprovider for a DropDownList in Flex.
The code is creating the IList correctly, and I can access the data inside just fine.
However, when I set the dataprovider for my DropDownList, it only shows b开发者_JS百科lank entries for each item in the list.
So, if I had 30 items in my IList, I will have 30 blank spots in my dropdown.
Here's the code I'm using.
categoryXML = new XML(loader.data);
for each(var category in categoryXML.category) {
categoryArr.addItem(category.name);
}
categoryList = categoryArr;
cats2.dataProvider = categoryList;
What could cause this? I can't seem to find anything via Google.
It's hard to tell without looking at your actual data. But, it appears you are creating an array of Strings. I have no idea how a Spark list handles simple values.
You might try something like this:
for each(var category in categoryXML.category) {
var newObject : Object = new Object();
newObject.label = category.name;
categoryArr.addItem(newObject.);
}
However, if category.name is a complex XML object, then you'll probably need to create a labelFunction. Something like this:
public myLabelFunction(item:Object):String{
return item.valueToDisplay;
}
And set it on the list like this:
myList.labelFunction = myLabelFunction;
精彩评论