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

    技术2022-05-20  64

    从服务器端读取数据加载到客户端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;

           }

          

        }

     


    最新回复(0)