简体   繁体   中英

itemEditEnd event in Flex DataGrid

So, I'm studying how to edit/validate input in a Flex 3 DataGrid cell. Here's the basic example I used for studying:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
        xmlns:mx="http://www.adobe.com/2006/mxml"   
        width="100%" height="100%" backgroundSize="100%">

    <mx:DataGrid editable="true" itemEditEnd="check(event)">

        <mx:columns>
            <mx:DataGridColumn headerText="Name" dataField="name"/>
            <mx:DataGridColumn headerText="Phone" dataField="phone"/>
        </mx:columns>

        <mx:dataProvider>
            <mx:ArrayCollection>
                <mx:Object name="John" phone="(69)2345-6798"/>
                <mx:Object name="Mary" phone="(69)1234-5678"/>
            </mx:ArrayCollection>
        </mx:dataProvider>

    </mx:DataGrid>

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import mx.events.DataGridEvent;
            import mx.collections.ArrayCollection;

            private function check(event:DataGridEvent):void{
                if(event.dataField == "phone"){
                    Alert.show("hi there!");
                }   
            }
        ]]>
    </mx:Script>

</mx:Application>

After compiling it and running the .swf, it only shows a grid with two rows; and after editing any of the phone numbers in the grid and clicking outside of it (meaning the edited cell loses focus, so Flex interprets this as "the edit has ended", thus triggering the itemEditEnd event, calling the check() function) the message "hi there!" will appear. My question is: why does it appear twice, if I'm only editing one phone number at a time? As far as I know, that message should only appear once for every time I edit the phone number, not twice. Is there something I'm missing about how the framework works?

It is like a bug. When I hit tab/enter or click in another cell. This generates the itemEditEnd event and moves the focus to a new editable cell.

In the event handler for the itemEditEnd event , an Alert is displayed. This pop up removes focus from that editable cell ... thus dispatching a second itemEditEnd event .

So, for that you have to put some logic for that to prevent second alert box. Like, set one boolean variable, and make true when alert once.

Same question ask already here.

Why does Alert.show() give me two Alert boxes?

And, many people getting the same issue before.

Hope it helps.

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