只是想知道是否有人知道子类ComboBox的现有组件,但是允许你在列表中指定一个标题为“all”或“none”的项目,将selectedItem设置为null?我已经考虑过编写一个,并且由于组件的内部结构看起来很多工作,所以我想知道是否有人已经完成了它?
答案 0 :(得分:0)
当没有选择项目时,ComboBox会是什么样子?或者为此选择的所有项目?听起来你应该使用List
代替ComboBox
。查看Tour de Flex上的列表控件。
答案 1 :(得分:0)
答案 2 :(得分:0)
运行:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" creationComplete="onCreationComplete()">
<mx:Script>
<![CDATA[
private var myData:Array = new Array();
[Bindable]
private var comboData:Array = new Array();
[Bindable]
private var selectedData:String = "";
private function onCreationComplete():void
{
myData.push({"label" : "First", "value" : "First"});
myData.push({"label" : "Second", "value" : "Second"});
myData.push({"label" : "Third", "value" : "Third"});
comboData.push({"label" : "<None>", "value" : "<None>"});
comboData.push({"label" : "<All>", "value" : "<All>"});
for(var i:int = 0; i < myData.length; i++) {
comboData.push(myData[i]);
}
}
private function onSmartComboBoxChange():void
{
if(smartComboBox.selectedItem) {
if(smartComboBox.selectedItem.value == "<None>") {
selectedData = "";
} else if(smartComboBox.selectedItem.value == "<All>") {
selectedData = "";
for(var i:int = 0; i < myData.length; i++) {
selectedData += myData[i].value + ", ";
}
} else {
selectedData = comboData[smartComboBox.selectedIndex].value;
}
}
}
]]>
</mx:Script>
<mx:VBox>
<mx:ComboBox id="smartComboBox" dataProvider="{comboData}" change="onSmartComboBoxChange()" labelField="label" />
<mx:Label id="selectedDataLabel" text="{selectedData}" />
</mx:VBox>
</mx:Application>