Flex中DataGrid怎么取得xml中的数据并绑定……
1个回答
展开全部
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
//////////////////////////////////////////////////////////////
// DataGrid
//
// editable ="false|true" *表格是否可编辑
// draggableColumns= "true|false" *列是否能抓取
// resizableColumns= "true|false" *列是否能重设大小
// sortableColumns = "true|false" *列是否能按大小排序
//
// AdvancedDataGrid
// sortExpertMode ="false|true" *是否可以按ctrl键进行子排序
//
//////////////////////////////////////////////////////////////
]]>
</mx:Script>
<mx:XMLList id="employees">
<employee>
<name>ABC</name>
<phone>001</phone>
<email>b</email>
<active>true</active>
</employee>
<employee>
<name>A</name>
<phone>002</phone>
<email>a</email>
<active>true</active>
</employee>
<employee>
<name>B</name>
<phone>001</phone>
<email>b</email>
<active>false</active>
</employee>
<employee>
<name>B</name>
<phone>002</phone>
<email>a</email>
<active>true</active>
</employee>
</mx:XMLList>
<mx:Panel title="DataGrid Control Example" height="100%" width="100%"
paddingTop="10" paddingLeft="10" paddingRight="10">
<mx:Label width="100%" color="blue"
text="Select a row in the DataGrid control."/>
<!-- DataGrid -->
<mx:DataGrid id="dg" rowCount="5" dataProvider="{employees}"
editable="true" dragEnabled="true" resizableColumns="true" sortableColumns="true" allowMultipleSelection="true">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" editable="false" />
<mx:DataGridColumn dataField="phone" headerText="Phone" draggable="false" editable="true"/>
<mx:DataGridColumn dataField="email" headerText="Email" sortable="false"/>
</mx:columns>
</mx:DataGrid>
<!-- AdvancedDataGrid -->
<mx:AdvancedDataGrid id="dg2" width="100%" height="100%" rowCount="5" dataProvider="{employees}"
editable="false" dragEnabled="true" resizableColumns="true" sortableColumns="true" sortExpertMode="true" >
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name" editable="false"/>
<mx:AdvancedDataGridColumn dataField="phone" headerText="Phone" draggable="false"/>
<mx:AdvancedDataGridColumn dataField="email" headerText="Email" sortable="true"/>
</mx:columns>
</mx:AdvancedDataGrid>
<!-- 表格数据绑定 -->
<mx:Form width="100%" height="100%">
<mx:FormItem label="Name">
<mx:Label text="{dg.selectedItem.name}"/>
</mx:FormItem>
<mx:FormItem label="Email">
<mx:Label text="{dg.selectedItem.email}"/>
</mx:FormItem>
<mx:FormItem label="Phone">
<mx:Label text="{dg.selectedItem.phone}"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
//////////////////////////////////////////////////////////////
// DataGrid
//
// editable ="false|true" *表格是否可编辑
// draggableColumns= "true|false" *列是否能抓取
// resizableColumns= "true|false" *列是否能重设大小
// sortableColumns = "true|false" *列是否能按大小排序
//
// AdvancedDataGrid
// sortExpertMode ="false|true" *是否可以按ctrl键进行子排序
//
//////////////////////////////////////////////////////////////
]]>
</mx:Script>
<mx:XMLList id="employees">
<employee>
<name>ABC</name>
<phone>001</phone>
<email>b</email>
<active>true</active>
</employee>
<employee>
<name>A</name>
<phone>002</phone>
<email>a</email>
<active>true</active>
</employee>
<employee>
<name>B</name>
<phone>001</phone>
<email>b</email>
<active>false</active>
</employee>
<employee>
<name>B</name>
<phone>002</phone>
<email>a</email>
<active>true</active>
</employee>
</mx:XMLList>
<mx:Panel title="DataGrid Control Example" height="100%" width="100%"
paddingTop="10" paddingLeft="10" paddingRight="10">
<mx:Label width="100%" color="blue"
text="Select a row in the DataGrid control."/>
<!-- DataGrid -->
<mx:DataGrid id="dg" rowCount="5" dataProvider="{employees}"
editable="true" dragEnabled="true" resizableColumns="true" sortableColumns="true" allowMultipleSelection="true">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" editable="false" />
<mx:DataGridColumn dataField="phone" headerText="Phone" draggable="false" editable="true"/>
<mx:DataGridColumn dataField="email" headerText="Email" sortable="false"/>
</mx:columns>
</mx:DataGrid>
<!-- AdvancedDataGrid -->
<mx:AdvancedDataGrid id="dg2" width="100%" height="100%" rowCount="5" dataProvider="{employees}"
editable="false" dragEnabled="true" resizableColumns="true" sortableColumns="true" sortExpertMode="true" >
<mx:columns>
<mx:AdvancedDataGridColumn dataField="name" headerText="Name" editable="false"/>
<mx:AdvancedDataGridColumn dataField="phone" headerText="Phone" draggable="false"/>
<mx:AdvancedDataGridColumn dataField="email" headerText="Email" sortable="true"/>
</mx:columns>
</mx:AdvancedDataGrid>
<!-- 表格数据绑定 -->
<mx:Form width="100%" height="100%">
<mx:FormItem label="Name">
<mx:Label text="{dg.selectedItem.name}"/>
</mx:FormItem>
<mx:FormItem label="Email">
<mx:Label text="{dg.selectedItem.email}"/>
</mx:FormItem>
<mx:FormItem label="Phone">
<mx:Label text="{dg.selectedItem.phone}"/>
</mx:FormItem>
</mx:Form>
</mx:Panel>
</mx:Application>
参考资料: 很久前网上找的例子,好像是flex examples,具体地址忘了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询