您的位置:首页 > 其它

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

2011-04-14 16:51 267 查看
从服务器端读取数据加载到客户端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;
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: