一个延迟加载Tree数据的例子
2008-06-27 18:22
501 查看
在有树型结构的应用中,很多时候这棵树的级树和数据量比较大,如果一次加载并生成整颗树时,往往并不可行,于是需要建立一棵延迟加载树,下面就是这样的一个例子,其中的代码我作了命名和注释的修改,原代码是以前摘自别的作者的。
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initTreeData()">
<mx:Script>
<![CDATA[
import mx.events.TreeEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var acSiteTreeList:ArrayCollection;
private function initTreeData():void {
var obj:Object;
acSiteTreeList = new ArrayCollection ();
for(var i:int = 0; i <3; i++) {
obj= new Object();
obj["type"] = "folder";
obj["children"] = new ArrayCollection();
//fetch is a property in the dataprovider to check if I have fetched the child nodes previously
//使用fetch来作是否生成下一级节点的依据
obj["fetch"] = false;
obj["label"] = "folder_" + i.toString();
acSiteTreeList.addItem(obj);
}
}
private function setView(event:TreeEvent):void {
if(event.item.type == "folder" && event.item.fetch == false) {
var obj:Object;
var item:Object;
var children:ArrayCollection;
for(var i:int = 0; i <acSiteTreeList.length; i++) {
obj= new Object();
obj["type"] = "node";
//如果当前节点有子节点的话,需要建立一个children的属性,这样会建立无穷级树
//obj["children"] = new ArrayCollection();
obj["fetch"] = false;
obj["label"] = "node_" + i.toString();
item = event.item;
children = item.children;
item.fetch = true;
children.addItem(obj);
acSiteTreeList.itemUpdated(item);
}
}
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="100%">
<mx:Tree id="treeSiteList" dataProvider="{acSiteTreeList}" x="204" y="10" height="582" width="394" itemOpen="setView(event)"></mx:Tree>
</mx:Canvas>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initTreeData()">
<mx:Script>
<![CDATA[
import mx.events.TreeEvent;
import mx.collections.ArrayCollection;
[Bindable]
private var acSiteTreeList:ArrayCollection;
private function initTreeData():void {
var obj:Object;
acSiteTreeList = new ArrayCollection ();
for(var i:int = 0; i <3; i++) {
obj= new Object();
obj["type"] = "folder";
obj["children"] = new ArrayCollection();
//fetch is a property in the dataprovider to check if I have fetched the child nodes previously
//使用fetch来作是否生成下一级节点的依据
obj["fetch"] = false;
obj["label"] = "folder_" + i.toString();
acSiteTreeList.addItem(obj);
}
}
private function setView(event:TreeEvent):void {
if(event.item.type == "folder" && event.item.fetch == false) {
var obj:Object;
var item:Object;
var children:ArrayCollection;
for(var i:int = 0; i <acSiteTreeList.length; i++) {
obj= new Object();
obj["type"] = "node";
//如果当前节点有子节点的话,需要建立一个children的属性,这样会建立无穷级树
//obj["children"] = new ArrayCollection();
obj["fetch"] = false;
obj["label"] = "node_" + i.toString();
item = event.item;
children = item.children;
item.fetch = true;
children.addItem(obj);
acSiteTreeList.itemUpdated(item);
}
}
}
]]>
</mx:Script>
<mx:Canvas width="100%" height="100%">
<mx:Tree id="treeSiteList" dataProvider="{acSiteTreeList}" x="204" y="10" height="582" width="394" itemOpen="setView(event)"></mx:Tree>
</mx:Canvas>
</mx:Application>
相关文章推荐
- 一个延迟加载Tree数据的例子 .
- 一个简单的例子演示:模仿微博里面的通过浏览器的滚动条来动态加载数据
- 关于ligerUI中ligerTree代码中的一个bug,造成该控件无法通过url的POST方式加载数据
- 一个通用的动态加载数据例子(IE5,NS6,Mozilla 1.3b)
- Hibernate的延迟加载,一个锋利的两面刀
- TabPanel多标签tab页加载同一个GridPanel显示不同的数据
- 一个内存数据交换的例子(一)
- jquery easyui tree 异步加载数据
- 记录Mybatis和Ehcache结合时启用延迟加载的一个坑
- Python操作json数据的一个简单例子
- 在ajax循环加载多条数据,并在内部定义一个函数
- 自己编写的一个Json工具类,实现了反射将整个Object转换为Json对象的功能,支持Hibernate的延迟加载对象
- 【Tree 3】树形结构数据加载的思考
- DLINQ(LINQ to SQL)之用户自定义函数、在不同的DataContext之间做更新、缓存、获取信息、数据加载选项和延迟加载
- 利用索引器搞定了一个通用字典数据加载方式。
- DHTMLX 前端框架 建立你的一个应用程序 教程(六)-- 表格加载数据
- 【项目分析】设计一种前端数据延迟加载的jQuery插件(2)
- Jquery实现延迟加载数据
- javascript树形菜单(一):Tigra Tree Menu,实现动态数据加载
- jquery的ajax返回json数据另外一个例子(不继承json-default)