如何将 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 打开 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>