开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜