一个延迟加载Tree数据的例子 .
2013-06-06 17:35
337 查看
在有树型结构的应用中,很多时候这棵树的级树和数据量比较大,如果一次加载并生成整颗树时,往往并不可行,于是需要建立一棵延迟加载树,下面就是这样的一个例子,其中的代码我作了命名和注释的修改,原代码是以前摘自别的作者的。
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
3. creationComplete="initTreeData()">
4. <mx:Script>
5. <![CDATA[
6.
7. import mx.events.TreeEvent;
8. import mx.collections.ArrayCollection;
9.
10.
11. [Bindable]
12. private var acSiteTreeList:ArrayCollection;
13.
14. private function initTreeData():void {
15. var obj:Object;
16. acSiteTreeList = new ArrayCollection ();
17. for(var i:int = 0; i <3; i++) {
18. obj= new Object();
19. obj["type"] = "folder";
20. obj["children"] = new ArrayCollection();
21. //fetch is a property in the dataprovider to check if I have fetched the child nodes previously
22. //使用fetch来作是否生成下一级节点的依据
23. obj["fetch"] = false;
24. obj["label"] = "folder_" + i.toString();
25. acSiteTreeList.addItem(obj);
26. }
27. }
28.
29. private function setView(event:TreeEvent):void {
30. if(event.item.type == "folder" && event.item.fetch == false) {
31.
32.
33. var obj:Object;
34. var item:Object;
35. var children:ArrayCollection;
36. for(var i:int = 0; i <acSiteTreeList.length; i++) {
37. obj= new Object();
38. obj["type"] = "node";
39. //如果当前节点有子节点的话,需要建立一个children的属性,这样会建立无穷级树
40. //obj["children"] = new ArrayCollection();
41. obj["fetch"] = false;
42. obj["label"] = "node_" + i.toString();
43. item = event.item;
44. children = item.children;
45. item.fetch = true;
46. children.addItem(obj);
47. acSiteTreeList.itemUpdated(item);
48. }
49. }
50. }
51. ]]>
52. </mx:Script>
53. <mx:Canvas width="100%" height="100%">
54. <mx:Tree id="treeSiteList" dataProvider="{acSiteTreeList}" x="204" y="10" height="582" width="394" itemOpen="setView(event)"></mx:Tree>
55. </mx:Canvas>
56.</mx:Application>
1.<?xml version="1.0" encoding="utf-8"?>
2.<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
3. creationComplete="initTreeData()">
4. <mx:Script>
5. <![CDATA[
6.
7. import mx.events.TreeEvent;
8. import mx.collections.ArrayCollection;
9.
10.
11. [Bindable]
12. private var acSiteTreeList:ArrayCollection;
13.
14. private function initTreeData():void {
15. var obj:Object;
16. acSiteTreeList = new ArrayCollection ();
17. for(var i:int = 0; i <3; i++) {
18. obj= new Object();
19. obj["type"] = "folder";
20. obj["children"] = new ArrayCollection();
21. //fetch is a property in the dataprovider to check if I have fetched the child nodes previously
22. //使用fetch来作是否生成下一级节点的依据
23. obj["fetch"] = false;
24. obj["label"] = "folder_" + i.toString();
25. acSiteTreeList.addItem(obj);
26. }
27. }
28.
29. private function setView(event:TreeEvent):void {
30. if(event.item.type == "folder" && event.item.fetch == false) {
31.
32.
33. var obj:Object;
34. var item:Object;
35. var children:ArrayCollection;
36. for(var i:int = 0; i <acSiteTreeList.length; i++) {
37. obj= new Object();
38. obj["type"] = "node";
39. //如果当前节点有子节点的话,需要建立一个children的属性,这样会建立无穷级树
40. //obj["children"] = new ArrayCollection();
41. obj["fetch"] = false;
42. obj["label"] = "node_" + i.toString();
43. item = event.item;
44. children = item.children;
45. item.fetch = true;
46. children.addItem(obj);
47. acSiteTreeList.itemUpdated(item);
48. }
49. }
50. }
51. ]]>
52. </mx:Script>
53. <mx:Canvas width="100%" height="100%">
54. <mx:Tree id="treeSiteList" dataProvider="{acSiteTreeList}" x="204" y="10" height="582" width="394" itemOpen="setView(event)"></mx:Tree>
55. </mx:Canvas>
56.</mx:Application>
相关文章推荐
- 一个延迟加载Tree数据的例子
- 关于ligerUI中ligerTree代码中的一个bug,造成该控件无法通过url的POST方式加载数据
- 一个简单的例子演示:模仿微博里面的通过浏览器的滚动条来动态加载数据
- 一个通用的动态加载数据例子(IE5,NS6,Mozilla 1.3b)
- 一个select接收socket数据的例子
- 一个数据汇总,列合并的例子
- Tree:加载列表数据
- Flex中如何通过给openItems属性设置一个XMLList或Array对象来打开Tree的一个节点的例子
- 一个mongo聚合数据的例子
- Google Earth & Asp.Net 一步一步从入门到精通(一)一个加载KML文档的例子
- Hibernate中对于数据的(增删改查)操作的一个例子的代码
- Python操作json数据的一个简单例子
- 一个EXTJS与JSP连接把数据写入数据库的例子
- 一个C/S结构的优秀例子: 延迟补偿在C/S架构游戏协议设计和优化中的应用
- jQuery EasyUI treegrid异步加载数据
- 一个GDAL的读写数据例子
- 无刷新取数据的一个例子
- 加载一个 IEnumerable 数据 界面出现逐行加载的效果
- 数据延迟加载
- WPF 中DataGrid控件绑定数据的一个例子