国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > WEB開發(fā) > 正文

5.7.在Tree控件中使用復(fù)雜數(shù)據(jù)對(duì)象

2024-04-27 13:51:57
字體:
供稿:網(wǎng)友
5.7.1問題
為Tree 控件傳遞復(fù)雜數(shù)據(jù),并使用Tree 適當(dāng)?shù)亟馕鏊鼈?br />5.7.2解決方法
在一個(gè)類中實(shí)現(xiàn)ITreeDataDescriptor 接口,并該類的新數(shù)據(jù)描述符中設(shè)置一個(gè)示例對(duì)象給Tree 中dataDescriptor 屬性,
5.7.3討論
使用一個(gè)對(duì)象和Tree 一起,將對(duì)象傳遞給Tree 來實(shí)現(xiàn)ITreeDataDescriptor 以解析數(shù)據(jù)并返回與數(shù)據(jù)中的對(duì)像關(guān)系相關(guān)的正確信息,XML 數(shù)據(jù)很容易將自己達(dá)到這個(gè)目的,但是復(fù)雜數(shù)據(jù)對(duì)象可以和為Tree 定義關(guān)系的對(duì)象一起被適當(dāng)?shù)氖褂?

下面的這個(gè)例子, ComplexDataType,是一個(gè)典型的復(fù)雜數(shù)據(jù)類型:
+展開
-ActionScript
package oreilly.cookbook {
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
public class ComplexDataType extends EventDispatcher {
public static const NAME_CHANGED:String = "nameChanged" ;
public static const OFFICE_CHANGED:String = "officeChanged" ;
public static const RECORD_CHANGED:String = "recordChanged" ;
private var _name:Name;
private var _office:Office;
private var _label:String;
public function ComplexDataType(target:IEventDispatcher=null ) {
super(target);
}
[Bindable(RECORD_CHANGED)]
public function set label(value:String):void {
_label = value;
dispatchEvent(newEvent(RECORD_CHANGED));
}
public function  get label():String { return _label; }
[Bindable(NAME_CHANGED)]
public function set name(value:Name):void {
_name = value;
dispatchEvent(newEvent(NAME_CHANGED));
}
public function get name():Name { return _name; }
[Bindable(OFFICE_CHANGED)]
public function set office(value:Office):void {
_office = value;
dispatchEvent(newEvent(OFFICE_CHANGED));
}
public function get office():Office { return _office; }
}
}


Office 和Name 對(duì)象都是由Office 對(duì)象的名字和地址組成的簡(jiǎn)單值對(duì)象,和firstName,lastName 屬性的Name 對(duì)象。沒有一個(gè)ITreeDataDescriptor 對(duì)象來描述ComplexDataType,Office 和Name 所有屬性之間的關(guān)系,Tree 將不能完全顯示這些對(duì)象的Array 和ArrayCollection,而將顯示Array 中不能使擴(kuò)展的兩個(gè)簡(jiǎn)單對(duì)象。

ITreeDataDescriptor 接口定義了以下數(shù)據(jù):

addChildAt(parent:Object, newChild:Object, index:int, model:Object =null):Boolean
這個(gè)方法插入了一個(gè)新的對(duì)象到結(jié)構(gòu)中,并決定新加對(duì)象放在數(shù)據(jù)結(jié)構(gòu)中的什么位置.

getChildren(node:Object, model:Object = null):ICollectionView

對(duì)于所有的結(jié)點(diǎn),這個(gè)方法決定這個(gè)結(jié)點(diǎn)或?qū)ο笫欠裼泻⒆咏Y(jié)點(diǎn)可以顯示,如果有孩子結(jié)點(diǎn),該方法將它們返回到CollectionView ,如果沒有,則返回空.

getData(node:Object, model:Object = null):Object
這個(gè)方法返回給定結(jié)點(diǎn)的所有數(shù)據(jù).

hasChildren(node:Object, model:Object = null):Boolean
這個(gè)方法決定該結(jié)點(diǎn)是否有孩子結(jié)點(diǎn)并返回一個(gè)布爾值.

isBranch(node:Object, model:Object = null):Boolean
這個(gè)方法測(cè)試該結(jié)點(diǎn)是否是最終結(jié)點(diǎn),并判斷其孩子結(jié)點(diǎn)是否能被顯示.

removeChildAt(parent:Object, child:Object, index:int, model:Object =null):Boolean
這個(gè)方法從結(jié)構(gòu)中移除一個(gè)對(duì)象并決定數(shù)據(jù)結(jié)構(gòu)中結(jié)點(diǎn)被移除后將會(huì)發(fā)生什么

ComplexDataType 的數(shù)據(jù)描述符正確執(zhí)行如下:
+展開
-ActionScript
package oreilly.cookbook {
import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.controls.treeClasses.ITreeDataDescriptor;
public class ComplexDataCollection implements ITreeDataDescriptor {
public function getChildren(node:Object,model:Object=null):ICollectionView{
var col:ArrayCollection;
if(node is Office){
col = newArrayCollection([node.officeAddress,node.officeName]);
return col;
}
if (node is Name){
col = new ArrayCollection([node.firstName, node.lastName]);
return col;
}
if (node is ComplexDataType){
col = new ArrayCollection([node.office, node.name]);
return col;
}
return null ;
}
public function hasChildren(node:Object, model:Object=null ):Boolean {
if (node is Office){
if (node.officeAddress != "" && node.officeName != "" ){
return true ;
else {
return false ;
}
}
if (node is Name){
if (node.firstName != "" && node.firstName != "" ){
return true ;
else { return false ; }
}
if (node is ComplexDataType){
if (node.office != null && node.name != null ) {
return true ;
else { return false ; }
}
return false ;
}
public function isBranch(node:Object, model:Object=null ):Boolean {
if (node is Office){
if (node.officeAddress != "" && node.officeName != "" ){
return true ;
else {
return false ;
}
}
if (node is Name) {
if (node.firstName != "" && node.firstName != "" ){
return true ;
else {
return false ;
}
}
if (node is ComplexDataType) {
if (node.office != null && node.name != null ) {
return true ;
else { return false ;
}
}
return true ;
}
public function getData(node:Object, model:Object=null ):Object {
if (node is Office) {
return {children:{label:node.officeName, label:node.officeAddress}};
}
if (node is Name) {
return {children:{label:node.firstName, label:node.lastName}};
}
if (node is ComplexDataType){
return {children:{label:node.office, label:node.name}};
}
return null ;
}
public function addChildAt(parent:Object, newChild:Object, index:int,model:Object=null):Boolean {
return false ;}
public function removeChildAt(parent:Object, child:Object, index:int,model:Object=null):Boolean {
return false ;
}
}
}

使用數(shù)據(jù)描述符并使Tree 控件完全顯示ComplexDataTypes 的數(shù)組,簡(jiǎn)單地設(shè)置一個(gè)之前代碼中說到的ComplexDataCollection 類的實(shí)例給Tree 的dataDescriptor 屬性:
+展開
-ActionScript
dataDescriptor="{new ComplexDataCollection()}"
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 图们市| 正定县| 噶尔县| 郧西县| 广安市| 开封县| 福清市| 呼图壁县| 从江县| 仪征市| 海阳市| 唐河县| 进贤县| 鹿邑县| 金溪县| 科技| 开江县| 固安县| 体育| 东山县| 浮山县| 铜川市| 太仆寺旗| 富平县| 兰溪市| 河源市| 嵩明县| 禄劝| 邵阳市| 佛冈县| 嘉义县| 宝丰县| 寿阳县| 霍林郭勒市| 肇源县| 牡丹江市| 石屏县| 西城区| 武陟县| 科尔| 铁岭县|