从服务器读取数据加载到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;
}
}
再一点需要注意的是,第一层和第二层的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;
}
}
相关文章推荐
- 从XML文件读取数据动态设置Tree控件使用
- 关于ligerUI中ligerTree代码中的一个bug,造成该控件无法通过url的POST方式加载数据
- asp.net:easyui tree控件加载url数据
- kendo listview 从服务器读取数据时加载菊花图(loading...)解决方案.
- 服务器控件如何自动加载回发数据
- 使用 ajax json(getJSON)从服务器读取数据,在IE下不更新问题解决
- 关于EXTJS 树(tree)的demo包括AsyncTreeNode 加载数据
- 加载数据库表全部数据到GridView控件,但通过查询条件在GridView显示一行或几行数据
- Bootstrap-Table实现从服务器加载数据进行显示
- ajax 技术同时加载多个结果集并赋于同一控件上解决数据冲突出现错乱现象方法
- Flex2 Tree从XML文件中加载数据
- 在jsp文件中读取本地SQL服务器中的数据。
- 数据绑定服务器控件
- jqgrid treegrid 重新加载数据
- AX ODBC读取其他SQL数据库服务器数据
- ASP.NET - 如何:对照数据类型验证 ASP.NET 服务器控件
- ASP.NET - 将数据绑定到 TreeView Web 服务器控件
- 一个延迟加载Tree数据的例子
- jsp 配置MySQL服务器 以及数据的插入和读取
- flex的tree动态加载大量数据与滚动条相关问题探讨