简体   繁体   中英

Flex selectedItem problems

I have encountered somthing a little strange in flex, possibly somthing im doing wrong but im not sure.

In two cases which i have noticed, when there is only 1 item in as:List or s:DropDownList for some reason when using list.selectedItem it appears as null. Using requireSelection="true" i know this isnt the case.

Has anyone else seen anything similar? or am i doing it completly wrong? Thanks Jon

Edit: In the code bellow it happens when clicking the edit document, which calls the open edit method

------------ Added Code ---------------------------

I have removed small portions to make it more readable

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

By default Spark's DropDownList displays a prompt if selectedIndex is -1, which will be the case if requireSelection is false and you have not otherwise set the list to a specific item. This would correspond with selectedItem being null.

The Spark ComboBox does something similar but it has a TextInput as you can type into it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM