问题
I have a spark list, which is based on a dataProvider. As the application runs, the data in the dataprovider can change, and also the dataProvider can be swapped for a different one
What I need to do is make sure that something is always selected in the list (unless it is empty)
回答1:
You simply have to set the property requireSelection
of your list instance to true
.
In MXML, it would be:
<s:List id="myList" requireSelection="true">
回答2:
After setting its data provider ( or whenever is changed ) you could do a:
myList.selectedIndex = 0;
, so whenever the is data on your list, its first item will be selected (it could be any index, just remember that it start from 0 to length - 1).
来源:https://stackoverflow.com/questions/2738447/how-do-i-make-sure-that-there-is-always-something-selected-in-a-spark-list