0

我创建了一个从 XML 文件中获取数据的网格。我需要获取整个行值并将它们相应地显示在下面的文本字段中。我能够实现所选行的行索引,但无法获取整个行数据。我尝试使用事件目标和网格选择索引

特此附上供参考的代码。

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                       xmlns:s="library://ns.adobe.com/flex/spark"
                       xmlns:mx="library://ns.adobe.com/flex/mx"
                       width="1186" height="646" backgroundColor="#FFFFFF"
                      
                       applicationComplete="srv.send()"
                       
                       >
    <s:layout>
        <s:BasicLayout/>
    </s:layout>
        

    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            import mx.core.mx_internal;
            import mx.events.FlexEvent;
                [Bindable]
            public function initFunc():void
            {
                thisButton.addEventListener("click",clickFunction);
            }
            
            **public function dada(event:Event):void
            {
            Alert.show(myGrid.selectedIndex.toString()+" "+event.target.text);
            naam.text=event.target.text
            
            }**

            protected function button1_creationCompleteHandler(event:FlexEvent):void
            {
                // TODO Auto-generated method stub
                
            }
            
        ]]>
        
        
        
    </fx:Script>
    <fx:Declarations>
        <mx:HTTPService id="srv" url="file:///C:/Users/Chaitanya.Galande/Desktop/first.xml">
        </mx:HTTPService>
    </fx:Declarations>

        
    
    <mx:VBox x="111" y="0" width="981" height="636" backgroundColor="#9CD0E3"
             contentBackgroundColor="#F5F5F5">
        <mx:DataGrid id="myGrid" width="856" click="dada(event)" color="#1B7DA6"
                     dataProvider="{srv.lastResult.Contacts.Contact}" fontSize="16">
            
        </mx:DataGrid>
        
        <mx:TextInput id="naam" text="dabcd"/>
        <mx:TextInput text="ada" id="age"/>
        <mx:TextInput text="ada" id="hobby"/>
        <mx:TextInput text="adasdadas" id="phone"/>
        <s:Button id="thisButton" height="39" label="Refresh" color="#9F41B6"
                  creationComplete="button1_creationCompleteHandler(event)" fontFamily="Courier New"
                  fontSize="20" fontStyle="normal" textDecoration="none" click="clickFunction(event)"/>
        <mx:Image source="a.png" />
    </mx:VBox>
</s:WindowedApplication>

4

1 回答 1

0

使用 selectedItem 而不是 selectedIndex 我在动画中使用 as3

于 2021-07-16T10:09:01.580 回答