2011-02-15 68 views
3

我在flex中遇到了一些有點奇怪的東西,可能是我做錯了 但我不知道。Flex selectedItem問題

在我注意到的兩種情況下,當s中只有一個項:List或s:DropDownList 出於某種原因使用list.selectedItem時,它顯示爲空。使用requireSelection =「true」 我知道情況並非如此。

有沒有其他人見過類似的東西?或者我是否完全錯誤? 感謝 喬恩

編輯:在代碼波紋管它點擊編輯文件,調用open編輯方法

------------添加的代碼時會發生---- -----------------------

我已刪除一小部分,以使其更易於閱讀

<s:TitleWindow width="486" height="300" title="Document Store" 
       xmlns:tmsbean="services.tmsbean.*" 
       close="close()"> 
    <fx:Declarations> 
     <s:CallResponder id="getAllAttachedDocumentsResult"/> 
     <tmsbean:TMSBean id="tMSBean" showBusyCursor="true"/> 
     <s:CallResponder id="removeDocumentLinkResult" result="getDocumentList()"/> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 


     private static var documentStoreView:DocumentStoreView = null; 
     [Bindable] 
     private var attachedToMenomic:String; 

     public static function getInstance():DocumentStoreView 
     { 
      if(documentStoreView == null){ 
       documentStoreView = new DocumentStoreView(); 
       DocumentForm.getInstance().addEventListener(DocumentFormEvent.DOCUMENT_ATTACHED,documentStoreView.getDocumentList); 
      } 
      return documentStoreView; 
     } 

     public function open(menomic:String,parent:DisplayObject):void 
     { 
      attachedToMenomic = menomic; 
      getDocumentList(); 
      PopUpManager.addPopUp(documentStoreView,parent,true); 
      PopUpManager.centerPopUp(documentStoreView); 
      y = y - 80; 
     } 

     public function close():void 
     { 
      PopUpManager.removePopUp(documentStoreView); 
     } 

     private function getDocumentList(evt:DocumentFormEvent = null):void 
     { 
      getAllAttachedDocumentsResult.token = tMSBean.getAllAttachedDocuments(attachedToMenomic); 
     } 


     private function openEdit():void{ 
      var editDsi:DocumentStoreItem = documentList.selectedItem as DocumentStoreItem; 
      Alert.show(editDsi.documentName); 
      DocumentForm.getInstance().openInEditMode(editDsi,this); 
     } 

    ]]> 
</fx:Script> 

<s:VGroup left="10" top="10" right="10" bottom="10"> 
    <s:List width="100%" height="100%" id="documentList" itemRenderer="com.documentStore.DocumentItemListRenderer" 
      dataProvider="{Utilitys.toArrayCollection(getAllAttachedDocumentsResult.token.result)}" /> 
    <s:HGroup horizontalAlign="right" width="100%"> 
     <s:Button label="Attach Document" click="{DocumentForm.getInstance().open(attachedToMenomic,this)}"/> 
     <s:Button label="Edit Document" click="openEdit()"/> 
    </s:HGroup> 
</s:VGroup> 
</s:TitleWindow> 
+0

List.selectedItem似乎對我有用,當有一個單數的項目和requireSelection =「true」設置。也許發佈一些代碼?在你檢查了什麼事件之後? – 2011-02-15 19:07:19

回答

2

默認火花的DropDownList中顯示一個prompt如果selectedIndex爲-1,情況將如此如果requireSelection爲假,並且您沒有以其他方式將列表設置爲特定項目。這將對應於selectedItem爲空。

Spark ComboBox做了類似的事情,但它有一個TextInput,您可以鍵入它。