flex中用ArrayCollection对象显示在Tree上: 目的:在数据库中查找对象,根据对象属性关系显示在Tree上
例如对象为:varsource:ArrayCollection=newArrayCollection([{departid:1,superId:0},{departid:...
例如对象为:
var source:ArrayCollection = new ArrayCollection(
[{departid:1,superId:0},
{departid:2,superId:1},
{departid:3,superId:2},
{departid:4,superId:2},
{departid:5,superId:2},
{departid:6,superId:3},
{departid:7,superId:3},
]);
该怎么操纵才能在Tree控件上显示出这两个属性的级别关系呢? 求大侠帮助。。。 展开
var source:ArrayCollection = new ArrayCollection(
[{departid:1,superId:0},
{departid:2,superId:1},
{departid:3,superId:2},
{departid:4,superId:2},
{departid:5,superId:2},
{departid:6,superId:3},
{departid:7,superId:3},
]);
该怎么操纵才能在Tree控件上显示出这两个属性的级别关系呢? 求大侠帮助。。。 展开
2个回答
展开全部
import mx.collections.ArrayCollection;
import mx.events.CollectionEvent;
public class ArrayCollectionForTree extends ArrayCollection
{
public var label:String;
public var parent:ArrayCollectionForTree;
public var children:ArrayCollectionForTree;
override public function addItem(item:Object):void
{
super.addItem(item);
if(item is ArrayCollectionForTree)
{
item.parent=this;
}
}
override public function addItemAt(item:Object,index:int):void
{
super.addItemAt(item,index);
if(item is ArrayCollectionForTree)
{
item.parent=this;
}
}
public function ArrayCollectionForTree(source:Array=null)
{
super(source);
children=this;
addEventListener(CollectionEvent.COLLECTION_CHANGE,notifitionParent);
}
private function notifitionParent(event:CollectionEvent):void
{
if(parent)
{
parent.itemUpdated(this);
}
}
}
import mx.events.CollectionEvent;
public class ArrayCollectionForTree extends ArrayCollection
{
public var label:String;
public var parent:ArrayCollectionForTree;
public var children:ArrayCollectionForTree;
override public function addItem(item:Object):void
{
super.addItem(item);
if(item is ArrayCollectionForTree)
{
item.parent=this;
}
}
override public function addItemAt(item:Object,index:int):void
{
super.addItemAt(item,index);
if(item is ArrayCollectionForTree)
{
item.parent=this;
}
}
public function ArrayCollectionForTree(source:Array=null)
{
super(source);
children=this;
addEventListener(CollectionEvent.COLLECTION_CHANGE,notifitionParent);
}
private function notifitionParent(event:CollectionEvent):void
{
if(parent)
{
parent.itemUpdated(this);
}
}
}
2012-10-15
展开全部
把它转成大概这样的格式,
new ArrayCollection(
[{d1,
children:new ArrayCollection([{d2,
children:new ArrayCollection([{d3,children:new ArrayCollection([{d6},{d7}])},{d4},{d5}])}])}
]);
new ArrayCollection(
[{d1,
children:new ArrayCollection([{d2,
children:new ArrayCollection([{d3,children:new ArrayCollection([{d6},{d7}])},{d4},{d5}])}])}
]);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询