Egret中tree组件使用案例,包含(文本过多时,自动换行功能)
下面代码结合http://bbs.egret.com/forum.php?mod=viewthread&tid=19028&page=1#pid133680这篇文章,修改exml;
private creatTree(): void { var dp: egret.gui.ObjectCollection = new egret.gui.ObjectCollection(); dp.source = { children: [{ dir: true,name: "TreeItem0",children: [{ name: "TreeItem00大娃娃吾问无为谓\r呜呜呜呜呜呜dawd" }, { dir: true,name: "TreeItem01",children: [{ name: "TreeItem010" }] }] }, { dir: true,name: "TreeItem1",children: [{ name: "TreeItem10" },{ name: "TreeItem11" }] },{ name: "TreeItem2" }] }; //设置数据源的父子关系,这样才会缩进 egret.gui.ObjectCollection.assignParent(dp.source,"children","parent"); //创建树 var tree: egret.gui.Tree = new egret.gui.Tree(); tree.labelField = "name"; tree.top = 20; tree.left = 20; tree.right = 20; tree.height = 300; tree.dataProvider = dp; tree.expandItem(dp.getItemAt(0),true); this.addChild(tree); // 还可以通过iconFunction,设置每一项前面显示的小图标: // tree.iconFunction = this.iconFunc; /*呈现项的icon筛选*/ } private iconFunc(item: any): any { if(item.dir) return "tree_icon_dir_png"; else return "tree_icon_file_png"; }
完整的项目案例:https://github.com/arvin0/EgretExamples/tree/master/GUI%20Tree