开发者

Flex - ComboBox labelFunction Not Refreshing With Updating of an ArrayCollection

开发者 https://www.devze.com 2023-01-11 14:36 出处:网络
I have two issues with my ComboBox. My first issue is that when my ArrayCollection only has one item, for some reason I cannot select that first item. The change function set on the mxml never gets c

I have two issues with my ComboBox.

My first issue is that when my ArrayCollection only has one item, for some reason I cannot select that first item. The change function set on the mxml never gets called when I try to select that one item. If I set a prompt, it works. I know that the item is not already selected because when debugging, the selected item shows null. I do not want to use a prompt. I want the first item in the ArrayCollection to be selected automatically. So if there is only one item, I want the selected item to be that. FYI - I am using a labelFunction to format开发者_StackOverflow中文版 the data in the Array Collection. Any idea why I cannot select the first item or set the first item in the ArrayCollection to be the selected item?

My bigger issue is that when my Array Collection gets updated, my label function must not be refreshing because when I first open the dropdown, it has specfic data. When the Array Collection gets updated and I open the dropdown again, I see the old data in the dropdown, yet it doesn't exist anymore.

So let's say I have a ComboBox that has a datasource of an array collection of one state code and it's state name. Their is a labelFunction that puts a dash in between the state code and the state name. Their is no prompt, so the ComboBox would look like GA - Georgia and when you open the dropdown, that would be all that is there. I want that item to be selected automatically. Any idea why the old data shows up when opening the dropdown after the array collection was updated with new data?

<mx:ComboBox labelFunction="getFormattedNpaNxxCollectionList()" 
     dataProvider="arrayColl" change="doSomething()"/>

public function getFormattedNpaNxxCollectionList(item:Object):String
{
  return StringUtil.substitute("{0} - {1}", item.stateCode, item.stateName);
}


Is the arrayColl declared as [Bindable] - the updates won't be reflected automatically if its not bindable. Post the code where you're updating the collection.

To select the first item if there's just one item after updating the array collection, you can call

if(arrayColl.length == 1)
  cb.selectedIndex = 0;

after the update.

If you are only updating the values in the collection (and not reassigning a whole new array collection object to arrayColl), you can do this from the collectionChange event handler of the array collection. Otherwise you have to do this after assigning the new collection object to the arrayColl variable.

0

精彩评论

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

关注公众号