从服务器读取数据加载到Tree控件上

从服务器端读取数据加载到客户端Tree控件上,如果是两层结构的话,就得在服务器端套两层List,以便和客户端的ArrayList对应。

再一点需要注意的是,第一层和第二层的labelField必须一致,比如下面: labelField都是bookName。

<mx:Tree labelField="bookName" showRoot="false" id="booksTree"
    dataProvider="{bookData}" width="100%" height="100%" dataDescriptor="{dataDescriptor}"/>

 

最重要的一点是要定义dataDescriptor 方法,实现ItreeDataDescriptor接口。这样才能实现二级菜单效果。

示例:

public class DatabaseDataDescriptor implements ITreeDataDescriptor

    {

      

       //we don't support drag and drop

       public function addChildAt(node:Object, child:Object, index:int, model:Object = null):Boolean

       {

           return false;

       }

      

       //we don't support drag and drop

       public function removeChildAt(node:Object, child:Object, index:int, model:Object=null):Boolean

       {

           return false;

       }

      

       //can't assume isBranch was called beforehand

       public function getChildren(node:Object, model:Object = null):ICollectionView

       {

           if (isBranch(node, model))

           {

              var booktype:BookType = node as BookType;

              return booktype.books;

           }

           return null;

       }

      

       //the node is the data

       public function getData(node:Object, model:Object = null):Object

       {

           return node;

       }

      

       //every DatabaseVO is a branch and TableVOs are the leaves

       public function isBranch(node:Object, model:Object = null):Boolean

       {

           return node is BookType;

       }

      

       //can't assume isBranch was called, return if tables.length > 0

       public function hasChildren(node:Object, model:Object=null):Boolean

       {

           return isBranch(node, model)

           && BookType(node).books != null

              && BookType(node).books.length > 0;

       }

      

    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值