开发者

flex conditional data provider to tree on the basis of list selection

This is my XML data in a file named nodesAndStuff.xml.

<?xml version="1.0" encoding="utf-8"?>
<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>

The component using this data source is an XMLListCollection which is bound to a spark List and the code for that is:

<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开发者_JAVA百科 {
            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>

Now I have added my tree just below the list and I have saved counting from 10 to 19 in one.xml, 20 to 29 in two.xml and so on in different XML file. I have no clue how to connect the XML containing counting from 10 to 19 as the single node in tree at the selection of label one in list.


There are all sorts of ways to do what you want to do. Keeping in the spirit of your example, I have modified it to do what I think you are asking:

<fx:Script>
    <![CDATA[
        private function init():void {
            processXML(one);
        }

        private function processXML(nodes:XML):void {
            xmlListColl.removeAll();
            xmlListColl.source = nodes.children();
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <fx:XML id="one" source="one.xml" />
    <fx:XML id="two" source="two.xml" />
</fx:Declarations>

<s:List id="lst"
        labelField="@label"
        horizontalCenter="0" verticalCenter="0">
    <s:dataProvider>
        <s:XMLListCollection id="xmlListColl" />
    </s:dataProvider>
</s:List>

<s:Button label="Change" click="processXML(two)" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜