Setting dataProvider to a comboBox
When setting an arrayCollection as a dataProvider to a comboBox programmatically,if the arrayCollection has just one element,i need to do a small validation:
> public resultHandler(event:ResultEvent):void{
arrColl = event.result.FlexData.ListData as ArrayCollection;
//to check if the arrColl has only one element开发者_开发技巧
if(arrColl == null)
myComboBox.dataProvider = event.result.FlexData.ListData
else
myComboBox.dataProvider = arrColl;
}
I would like to know,if there is a way to skip this validation every time.Is there a way to set dataProvider such that i dont have to check if the collection has one or more elements?
There is no built-in way to do this.
You'll need to either:
create a utility method that does this. For instance
myComboBox.dataProvider = ComboBoxUtil.setDataProvider(collection);
subclass the ComboBox control and override the dataProvider setter where you can include this logic
精彩评论