填充树使用XML文件 [英] Populate Tree Using xml file

查看:193
本文介绍了填充树使用XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

帮助,

在MXML我可以加载XMLFILE为XMLListCollection在运行时使用的HTTPService,然后赋值给一个列表对象。

In mxml I can load an xmlfile into an xmllistcollection at runtime using an httpservice, and then assign that to a list object.

我还可以定义XML对象的菜单树结构中的code并将其分配给一棵树。

I can also define an xml object menu tree structure in the code and assign it to a tree.

我不能做的是加载XML文件在运行时并将其分配给一棵树。

What I can't do is load the xml file at runtime and assign it to a tree.

所以我试图加载一个文件:

So I'm trying to load a file:

<root>
 <menuitem name="First Main Item">
   <menuitem name = "sub item 1"/>
   <menuitem name = "sub item 2"/>
 </menuitem>
 <menuitem name="First Main Item">
   <menuitem name = "sub item 3"/>
   <menuitem name = "sub item 4"/>
 </menuitem>
</root>

成一树在运行时。

into a tree at runtime.

任何线索,如何做到这一点?

Any clues as to how to do this?

推荐答案

只需使用的HTTPService将请求发送给您的URL。 Tree组件使用List作为数据提供者,所以你需要使用

Just use a HTTPService to send a request to your URL. The Tree component uses a List as data provider, so you need to use

dataProvider="{myXml.menuitem}"

你的XML转换成一个列表。不要忘记定义树的labelField属性

to convert your XML to a List. Don't forget to define a labelField of your tree

labelField="@name"

下面的树:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600" 
           creationComplete="myService.send()">
<fx:Declarations>
    <s:HTTPService id="myService" url="com/xmltree/tree.xml" resultFormat="e4x" result="onServiceResult(event)"/>
</fx:Declarations>

<fx:Script>
    <![CDATA[
        import mx.rpc.events.ResultEvent;

        [Bindable]private var myXml:XML;

        private function onServiceResult(event:ResultEvent):void
        {
            myXml = event.result as XML;
        }
    ]]>
</fx:Script>

<s:HGroup x="20" y="20">
    <mx:Tree 
        dataProvider="{myXml.menuitem}" 
        labelField="@name"/>
</s:HGroup>

</s:Application>

这篇关于填充树使用XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆