日期:2014-05-16 浏览次数:20501 次
import mx.collections.ArrayCollection; import mx.collections.XMLListCollection; import mx.containers.Panel; import mx.controls.Tree; import mx.core.ClassFactory; import mx.events.ListEvent; //这里写的是hard data //实际操作时 从数据库读取数据 private var companyEmployee:Array=[ {employeeGroup:"理疗师组", employeeID:1, employeeName:"张强", employeeRegPlace:"总部店"}, {employeeGroup:"烫染师组", employeeID:11, employeeName:"罗超", employeeRegPlace:"总部店"}, {employeeGroup:"设计师组", employeeID:12, employeeName:"当当", employeeRegPlace:"总部店"}, {employeeGroup:"前台收银", employeeID:3, employeeName:"伟伟", employeeRegPlace:"总部店"}, {employeeGroup:"伙伴员组", employeeID:7, employeeName:"罗兵", employeeRegPlace:"总部店"}, {employeeGroup:"烫染师组", employeeID:8, employeeName:"超超", employeeRegPlace:"城南店"}]; private var company:Array=[ {companyName:"总部店", id:"1"}, {companyName:"城南店", id:"2"}]; private function init():void { /**** * 相同组的员工可能不止一人 * 理疗师组------分析数据并归组 * **/ AnalyzeEmployeeGroup(); } private var AnalyzedACOData:ArrayCollection=new ArrayCollection() private function AnalyzeEmployeeGroup():void { for (var k:int=0; k < companyEmployee.length; k++) { var obj:Object=new Object(); var obj2:Object=new Object() var childrenACO:ArrayCollection=new ArrayCollection(); if (k == 0) { obj.employeeGroup=companyEmployee[k].employeeGroup; childrenACO.addItem(companyEmployee[k]) obj.children=childrenACO; AnalyzedACOData.addItem(obj) } else { //判断companyEmployee[k].employeeGroup是否在数组中,如果存在, //取得其索引,加入children //否则 新加入数组 var returnNum:Number=findIsDataInArrays(companyEmployee[k].employeeGroup); //找到有 if (returnNum != -1) { //索引值 var idx:Number=findDataInArraysOrder(companyEmployee[k].employeeGroup); var oldObj:Object=AnalyzedACOData.getItemAt(idx); ArrayCollection(oldObj.children).addItem(companyEmployee[k]) } else { //没有找到 obj.employeeGroup=companyEmployee[k].employeeGroup; childrenACO.addItem(companyEmployee[k]) obj.children=childrenACO; AnalyzedACOData.addItem(obj); } } } customTreeData() } private function findIsDataInArrays(input:String):Number { for (var i:int=0; i < AnalyzedACOData.length; i++) { if (AnalyzedACOData[i].employeeGroup === input) { retu