Get changed value of Item from ItemRenderer in List

泪湿孤枕 提交于 2019-12-11 18:25:46

问题


I have a List with textInput as itemrenderer. Initially the list is loaded with data from a data provider. However since the items are rendered in textInputs, I have the ability to change the value of a particular item.

But when trying to access the value of the changed item using the function below, I still get the old value in my trace:

private function addItem(event:Event):void {
    trace(myDataProvider.getItemAt(myList.selectedIndex).label);
}

can someone tell me what I need to do for the new value to be available. My itemrenderer is shown below:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                xmlns:components="components.*"
                >
<s:layout> 
    <s:HorizontalLayout/> 
</s:layout> 

<fx:Script>
    <![CDATA[


        override public function set data( value:Object ) : void {
            super.data = value;
        }

        protected function myTextInput_enterHandler(event:FlexEvent):void
        {

            trace(myTextInput.text);
                            What Next??


        }


    ]]>
</fx:Script>

<components:myComp1 text="{data.label}" id="myTextInput" enter="myTextInput_enterHandler(event)"/>
</s:ItemRenderer>

Thanks for your help..anyone.


回答1:


Try to use:

<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" 
                xmlns:components="components.*"
                >
<s:layout> 
    <s:HorizontalLayout/> 
</s:layout> 

<fx:Script>
    <![CDATA[


        override public function set data( value:Object ) : void {
            super.data = value;
        }

        protected function myTextInput_enterHandler(event:FlexEvent):void
        {
            trace(myTextInput.text);
            data.label = myTextInput.text;
        }


    ]]>
</fx:Script>

<components:myComp1 text="{data.label}" id="myTextInput" enter="myTextInput_enterHandler(event)"/>
</s:ItemRenderer>


来源:https://stackoverflow.com/questions/6437634/get-changed-value-of-item-from-itemrenderer-in-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!