Flex selectedItem problems

I came across something a bit strange in flex, maybe something that I am doing wrong but I'm not sure.

In two cases that I noticed when there was only 1 element in the s: List: DropDownList for some reason, when using list.selectedItem it appears as null. Using requireSelection = "true" I know that it is not.

Has anyone else seen something like this? or am I doing this completely wrong? thanks John

Edit: In the code below, this happens when you click on an editable document that calls the open editing method

------------ Added code ---------------------------

I 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>
+3
source share
1

Spark DropDownList prompt, selectedIndex -1, , requireSelection - false . , selectedItem null.

Spark ComboBox - , TextInput, .

+2

Source: https://habr.com/ru/post/1792283/


All Articles