2009-03-03 7 views
0

Folgende Anzeigen eine ComboBox mit dem Text "One Select":Kann ich eine bindbare Zeichenfolge für eine ComboBox-Eingabeaufforderung verwenden?

** Dies ist Pseudo-Code *

<?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> 

jedoch folgende Anzeigen eine ComboBox mit dem Text "Ziel 1" (das Label des ersten Artikels):

<?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> 

Warum kann ich keine Bindable String für die Eingabeaufforderung verwenden ???

Antwort

0

Das funktionierte:

<?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> 

ich nicht herausfinden können, warum ich selectedIndex auf -1 explizit festgelegt haben, aber es funktioniert!

+0

Die Bindung erfolgt etwas später als die Komponentenerstellung. Ich vermute, dass die ComboBox standardmäßig das erste Element auswählt, wenn Sie keine Eingabeaufforderung angeben. Also, die ComboBox wird erstellt, validiert und wählt das erste Element, und dann wird die Bindung eingefügt. – joshtynjala

+0

Ja, das macht Sinn. –

Verwandte Themen