以下显示带有“Select One”文本的ComboBox:
**这是伪代码*
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:ComboBox prompt="Select One">
<mx:dataProvider>
<mx:Array>
<mx:Object label="Obj 1" />
<mx:Object label="Obj 2" />
<mx:Object label="Obj 3" />
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
</mx:Application>
但是,以下显示带有文本“Obj 1”的ComboBox(第一项的标签):
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
[Bindable]
private var promptText:String = "Select One";
]]>
</mx:Script>
<mx:ComboBox prompt="{promptText}">
<mx:dataProvider>
<mx:Array>
<mx:Object label="Obj 1" />
<mx:Object label="Obj 2" />
<mx:Object label="Obj 3" />
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
</mx:Application>
为什么我不能使用Bindable String来提示???
答案 0 :(得分:0)
这有效:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
[Bindable]
private var promptText:String = "Select One";
]]>
</mx:Script>
<mx:ComboBox selectedIndex="-1" prompt="{promptText}">
<mx:dataProvider>
<mx:Array>
<mx:Object label="Obj 1" />
<mx:Object label="Obj 2" />
<mx:Object label="Obj 3" />
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>
</mx:Application>
我无法弄清楚为什么我必须将selectedIndex显式设置为-1,但是,它有效!