在flex中实现下拉选择树,有很多种方法,比如(代码仅为示例):
1)mx:ComboBox中设置dropdownFactory为mx:Tree或其子类
<mx:ComboBox>
<mx:dropdownFactory>
<fx:Component >
<mx:Tree/>
</fx:Component>
</mx:dropdownFactory>
</mx:ComboBox>
2)mx:PopUpButton中设置popUp属性
<mx:PopUpButton
creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
protected function creationCompleteHandler(event:FlexEvent):void
{
var tree:Tree = new Tree();
this.popUp = tree;
}]]></fx:script></mx:PopUpButton>
但使用中发现很容易误操作,即下拉选择的时候不小心选中了节点,从而关闭了下拉树,如何阻止呢?
查看源码之后,发现设置PopUpButton的closeOnActivity=false即可,但ComboBox因为相关属性和方法都是私有,实现起来太曲折