Using an XML data provider with the Spark List control in Flex 4
2012-12-17 16:53
555 查看
Using an XML data provider with the Spark List control in Flex 4
by PETER DEHAAN on NOVEMBER 4, 2009in LIST (SPARK), XML, XMLLIST, XMLLISTCOLLECTION, BETA2
The following example shows how you can use an XML document as a data provider for a Spark List control in Flex 4 by using an XMLListCollection.
Full code after the jump.
The following example(s) require Flash Player 10 and the Adobe Flex 4 SDK. To download the Adobe Flash Builder 4 trial, seehttp://www.adobe.com/products/flex/. To download the latest nightly build of the Flex 4 SDK, seehttp://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4.
For more information on getting started with Flex 4 and Flash Builder 4, see the official Adobe Flex Team blog.
<?xml version="1.0"?> <!-- http://blog.flexexamples.com/2009/11/04/using-an-xml-data-provider-with-the-spark-list-control-in-flex-4/ --> <s:Application name="Spark_List_dataProvider_XML_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <s:List id="lst" labelField="@label" horizontalCenter="0" verticalCenter="0"> <s:dataProvider> <s:XMLListCollection> <fx:XMLList xmlns=""> <node label="One" /> <node label="Two" /> <node label="Three" /> <node label="Four" /> <node label="Five" /> <node label="Six" /> <node label="Seven" /> <node label="Eight" /> <node label="Nine" /> </fx:XMLList> </s:XMLListCollection> </s:dataProvider> </s:List> </s:Application>
Or, if you wanted to embed the XML into your application, you could use the <fx:XML/> tag and bind to an XMLListCollection, as seen in the following example:
<?xml version="1.0"?> <!-- http://blog.flexexamples.com/2009/11/04/using-an-xml-data-provider-with-the-spark-list-control-in-flex-4/ --> <s:Application name="Spark_List_dataProvider_XML_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo"> <fx:Declarations> <fx:XML id="nodes" source="nodesAndStuff.xml" /> </fx:Declarations> <s:List id="lst" labelField="@label" horizontalCenter="0" verticalCenter="0"> <s:dataProvider> <s:XMLListCollection source="{nodes.children()}" /> </s:dataProvider> </s:List> </s:Application>
And the external .XML file, nodesAndStuff.xml, is as follows:
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2009/11/04/using-an-xml-data-provider-with-the-spark-list-control-in-flex-4/ --> <root> <node label="One" /> <node label="Two" /> <node label="Three" /> <node label="Four" /> <node label="Five" /> <node label="Six" /> <node label="Seven" /> <node label="Eight" /> <node label="Nine" /> </root>
Or, if you didn’t want to use data binding, Corey, you could set the data provider using ActionScript, as seen in the following example:
<?xml version="1.0"?> <!-- http://blog.flexexamples.com/2009/11/04/using-an-xml-data-provider-with-the-spark-list-control-in-flex-4/ --> <s:Application name="Spark_List_dataProvider_XML_test" xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" initialize="init();"> <fx:Script> <![CDATA[ private function init():void { xmlListColl.source = nodes.children(); } ]]> </fx:Script> <fx:Declarations> <fx:XML id="nodes" source="nodesAndStuff.xml" /> </fx:Declarations> <s:List id="lst" labelField="@label" horizontalCenter="0" verticalCenter="0"> <s:dataProvider> <s:XMLListCollection id="xmlListColl" /> </s:dataProvider> </s:List> </s:Application>
This entry is based on a beta version of the Flex 4 SDK and therefore is very likely to change as development of the Flex SDK continues. The API can (and will) change causing examples to possibly not compile in newer versions of the Flex 4 SDK.
相关文章推荐
- Setting an effect when the items in a data provider change on a List control in Flex
- Creating a Web Control with an Expandable Property in the Designer by Using C#.
- using JS to control two select(html),the data can be loaded from database and XML,and show in the select
- Working with Data in ASP.NET 2.0 :: Using TemplateFields in the GridView Control
- Accessing List Data using the JavaScript Client OM and displaying in a Dialog
- An implementation of the skip list data structure written in C++
- Coding in the Shade: Using Eclipse with Google Data APIs
- Using ASP.NET 3.5's ListView and DataPager Controls: Grouping Data with the ListView Control (翻译)
- Creating a radio button item renderer on a Spark List control in Flex 4
- Using XSLT files with the new XMLDataSource control(转)
- Fixing the "There is already an open DataReader associated with this Command which must be closed first." exception in Entity Framework
- Using the HTMLControl Class in Adobe AIR to parse HTML as a data source
- Implementing Virtual Mode with Just-In-Time Data Loading in the Windows Forms DataGridView Control
- Transforms XML data using an XSLT style sheet with C#
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268
- Along with all the above benefits, you cannot overlook the space efficiency and performance gains in using DataFrames and Dataset APIs for two reasons.
- Using a custom context menu with the Flex DataGrid control
- Android: Reading, using and working with XML data and web services in Android
- Opening nodes in a Flex Tree control using the expandItem() method
- Building data-driven map applications using the Flex DataMap control