0

xml ファイルのデータを datagrid に取得する方法 (データ グリッドには、sno、status、register、join(join はボタン) などの列があります)。結合ボタンがクリックされるたびに、xml ファイルのデータを使用してデータグリッド内のデータを変更および更新するにはどうすればよいですか。私が書いたコードを添付します。あなたの誰かがこの問題を解決できるなら、私は感謝します。これはmxmlコードです。``

<mx:XML id="tempXML"  source="data/data.xml" />

<mx:XMLListCollection id="dataXMLList"  source="{tempXML.start}" />

        <mx:XML id="updateXML" source="data/update.xml"/>
        <mx:XMLListCollection id="FirstXMLList" source="{updateXML.First}"/>
        <mx:XMLListCollection id="SecondXMLList" source="{updateXML.Second}"/>
        <mx:XMLListCollection id="ThirdXMLList" source="{updateXML.Third}"/>
        <mx:XMLListCollection id="InitFirstXMLList" source="{updateXML.InitFirst}"/>

<mx:Script>
    <![CDATA[
           import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
           import mx.collections.ArrayCollection;
           public var selectedrow:int=new int();


             public function onClick(item:Object):void
              {

                  if(datagrid.selectedIndex==0)
                  {
                    datagrid.dataProvider=FirstXMLList; 

                  }
                  else if(datagrid.selectedIndex==1)
                  {
                    datagrid.dataProvider=SecondXMLList;
                  }
                  else if(datagrid.selectedIndex==2)
                  {
                    datagrid.dataProvider=ThirdXMLList;
                  }

               } 
               public function secondClick(item:Object):void
               {
                   b1.visible=false;
                   b2.visible=true;
                    do
                  {
                      datagrid.dataProvider=InitFirstXMLList;
                  }
                  while(datagrid.selectedIndex==0)
               }


    ]]>
</mx:Script>

<mx:VBox>
    <mx:AdvancedDataGrid id="datagrid" dataProvider="{dataXMLList}" sortExpertMode="true" x="368" y="56" height="252" resizableColumns="false" sortableColumns="false" draggableColumns="false" editable="false">
<mx:columns>
    <mx:AdvancedDataGridColumn headerText="Sno"  dataField="sno" />
    <mx:AdvancedDataGridColumn headerText="Status" dataField="status"  />
    <mx:AdvancedDataGridColumn headerText="REG Table" dataField="reg"  />

    <mx:AdvancedDataGridColumn id="b1" headerText="JOIN">
        <mx:itemRenderer>
            <mx:Component >
                <mx:Button  label="JOIN" click="{outerDocument.onClick(data)}" />
            </mx:Component>
        </mx:itemRenderer>

    </mx:AdvancedDataGridColumn>
    <mx:AdvancedDataGridColumn  id="b2" headerText="JOIN" visible="false">
        <mx:itemRenderer>
            <mx:Component >
                <mx:Button  label="JOIN" click="{outerDocument.secondClick(data)}" />
            </mx:Component>
        </mx:itemRenderer>

    </mx:AdvancedDataGridColumn>
</mx:columns>

</mx:VBox>

data.xml ファイル..... ここにコードを入力してください 1 open 0/2

    <start>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </start>

    <start>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </start>

 </DATA>

the update.xml file ....                                                                enter code here<?xml version="1.0" encoding="UTF-8"?>
<Update version="1">
   <First>
   <sno>1</sno>
   <status>Running</status>
   <reg>1/2</reg>
   </First>

    <First>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </First>

    <First>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </First>

   <Second>
   <sno>1</sno>
   <status>open</status>
   <reg>0/2</reg>
   </Second>

    <Second>
   <sno>2</sno>
   <status>Running</status>
   <reg>1/2</reg>
   </Second>

    <Second>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </Second>

     <Third>
   <sno>1</sno>
   <status>open</status>
   <reg>0/2</reg>
   </Third>

   <Third>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </Third>

   <Third>
   <sno>3</sno>
   <status>Running</status>
   <reg>1/2</reg>
   </Third>

   <InitFirst>
   <sno>1</sno>
   <status>open</status>
   <reg>1/2</reg>
   </InitFirst>

   <InitFirst>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitFirst>

    <InitFirst>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitFirst>

    <InitSecond>
   <sno>1</sno>
   <status>open</status>
   <reg>1/2</reg>
   </InitSecond>

   <InitSecond>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitSecond>

    <InitSecond>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitSecond>

    <InitThird>
   <sno>1</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitThird>

   <InitThird>
   <sno>2</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitThird>

    <InitThird>
   <sno>3</sno>
   <status>open</status>
   <reg>0/2</reg>
   </InitThird>

    </Update>
4

1 に答える 1

0

Flex Examples ブログは良い例を提供しています:

データグリッド

XML

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<FLVCoreCuePoints version="1">   

    <CuePoint>
        <Time>0</Time>
        <Type>event</Type>
        <Name>slide1</Name>
        <Parameters>
            <Parameter>
                <Name>id</Name>
                <Value>value</Value>
            </Parameter>
        </Parameters>
    </CuePoint>   

    <CuePoint>
        <Time>5000</Time>
        <Type>event</Type>
        <Name>slide2</Name>
        <Parameters>
            <Parameter>
                <Name>param1</Name>
                <Value>value1</Value>
            </Parameter>
            <Parameter>
                <Name>param2</Name>
                <Value>value2</Value>
            </Parameter>
        </Parameters>
    </CuePoint>   

    <CuePoint>
        <Time>20000</Time>
        <Type>event</Type>
        <Name>slide3</Name>
    </CuePoint>   

</FLVCoreCuePoints>

MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/07/26/displaying-xml-data-in-a-datagrid/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                layout="vertical"
                verticalAlign="top"
                backgroundColor="white">

    <mx:XML id="tempXML"
            source="assets/cuePoints.xml" />

    <mx:XMLListCollection id="cuePointXMLList"
                          source="{tempXML.CuePoint}" />
    <mx:XMLListCollection id="parametersXMLList"
                          source="{dataGrid.selectedItem.Parameters.Parameter}" />

    <mx:Script>
        <![CDATA[
            private function parametersLabelFunction(item:Object, column:DataGridColumn):String
            {
                return item.Parameters.Parameter.length();
            }

            private function numericSortCompareFunction(objA:Object, objB:Object):int
            {
                var itemA:Number = parseInt(objA.Time.text()) as Number;
                var itemB:Number = parseInt(objB.Time.text()) as Number;

                if (itemA > itemB)
                {
                    return 1;
                }
                else if (itemA < itemB)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        ]]>
    </mx:Script>

    <mx:VBox>
        <mx:DataGrid id="dataGrid"
                     dataProvider="{cuePointXMLList}"
                     width="100%"
                     rowCount="{cuePointXMLList.length + 1}">
            <mx:columns>
                <mx:DataGridColumn id="timeCol"
                                   dataField="Time"
                                   headerText="Time (ms):"
                                   sortCompareFunction="numericSortCompareFunction" />
                <mx:DataGridColumn id="typeCol"
                                   dataField="Type"
                                   headerText="Type:" />
                <mx:DataGridColumn id="nameCol"
                                   dataField="Name"
                                   headerText="Name:" />
                <mx:DataGridColumn id="parametersCol"
                                   dataField="Parameters"
                                   headerText="Parameters:"
                                   labelFunction="parametersLabelFunction" />
            </mx:columns>
        </mx:DataGrid>

        <mx:DataGrid id="parametersDataGrid"
                     dataProvider="{parametersXMLList}"
                     width="100%"
                     visible="{parametersXMLList.length > 0}"
                     rowCount="{parametersXMLList.length + 1}">
            <mx:columns>
                <mx:DataGridColumn id="parameterNameCol"
                                   dataField="Name"
                                   headerText="Parameter Name:" />
                <mx:DataGridColumn id="parameterValueCol"
                                   dataField="Value"
                                   headerText="Parameter Value:" />
            </mx:columns>
        </mx:DataGrid>
    </mx:VBox>

</mx:Application>
于 2013-06-05T06:33:36.187 に答える