Flex4. Get the second item from DropDownList
Does any one know how it's possible to get in Flex 4 a value of the second item from Drop Down list, assuming I have 3 items listed there? E.g.
- 5
- 4
- 9
I need 4
MyLable.text=myDDList.dataProvider.getItemAt(1).toString();
this开发者_高级运维 one doesn't work
Without knowing your dataProvider structure; it is impossible to give you a definite answer. This code will give you the object being displayed in the second item of the DropDownList:
var tempObject : Object = myDDList.dataProvider.getItemAt(1);
Using the default labelField, that object should have a field named label on it which will return your suggested value:
MyLable.text = tempObject['label'];
You can even make this slightly more flexible:
MyLable.text = tempObject[myDDList.labelField];
If you are using a labelFunction; you'll have to run your object through the labelFunction procedure.
If you're using custom objects in your dataProvider, you can use the approach in your own answer if you implement a toString() method in that object which returns the '4' string.
精彩评论