Chinaunix首页 | 论坛 | 博客
  • 博客访问: 362290
  • 博文数量: 100
  • 博客积分: 2586
  • 博客等级: 少校
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-09 15:20
个人简介

我是一个Java爱好者

文章分类

全部博文(100)

文章存档

2014年(2)

2013年(7)

2012年(2)

2010年(44)

2009年(28)

2008年(17)

我的朋友

分类:

2010-02-23 11:35:41

通常情况下,你可以从服务器上为tree控件取得XML数据 ,你也可以在Tag里直接定义格式良好的XML数据。

你可以使用或者Tag在mxml里定义XML数据。

你可以将XML object直接作为一个层级数据控件的dataProvider,however,if the object changes dynamically,你应该做如下处理:
1,将XML或者XMLList objects转换为XMLListCollection;
2,通过修改XMLListCollection数据来更新原始的XML数据;     更多……

XMLListCollection支持IList和ICollectionView两个接口,所以它能实现access,sort,filter等等操作:
get,set,add,remove
同时支持IViewCursor接口,于是可以实现Cursor功能:
一个Array,ArrayCollection,ICollectionView和IViewCursor之间的关系的例子如下:

var myAC:ArrayCollection=new ArrayCollection(myArray);
var myCursor:IViewCursor=myAC.CreateCursor();
while(!myCursor.afterLast){myCursor.moveNext();}

以下例子显示了两个Tree,一个使用XML作为数据源,一个使用XMLListCollection作为数据源




    
        
            
                
                
                
                
            
            
                
                
                
                
            
        
    

    
    

    
    
    
     

从上面的例子可以看出,E4X标准的XML数据必须具有一个根节点,而为了阻止这个根节点在类似tree或者
Menu-Based这样的层级数据显示控件显示根节点呢,我们必须设置showRoot属性为false;
其次,当您使用XML,XMLList,XMLListCollection作为类似tree数据显示控件的数据源的时候,
你 必须明确指定这些控件的labelField 属性,即使XMLattributes里有一个label,
You must do this because you must use the @ sign to signify an attribute!
XMLListCollection提供对数据源的dynamically updates,但是XMLList和XML不行。
addItem,addItemAt,setItemAt,getItemIndex,removeItemAt
XMLListCollection的CollectionEvent事件:
public function collectionEventHandler(event:CollectionEvent):void {
         switch(event.kind) {
             case CollectionEventKind.ADD:
                 addLog("Item "+ event.location + " added");
                 break;
             case CollectionEventKind.REMOVE:
                 addLog("Item "+ event.location + " removed");
                 break;
             case CollectionEventKind.REPLACE:
                 addLog("Item "+ event.location + " Replaced");
                 break;
             case CollectionEventKind.UPDATE:
                 addLog("Item updated");
                 break;
         }
}
--------------------------------------------------------------------



    
    
                
                    
                    
                    
                
                
                    
                    
                    
                
                
                    
                    
                    
                
            ;

        // An XMLListCollection representing the data for the shopping List.
        [Bindable]
        public var listDP:XMLListCollection = new XMLListCollection(new XMLList());

        // Add the item selected in the Tree to the List XMLList data provider.
        private function doTreeSelect():void
        {
            if (prodTree.selectedItem)
                listDP.addItem(prodTree.selectedItem);
        }

        // Remove the selected in the List from the XMLList data provider.
        private function doListRemove():void
        {
            if (prodList.selectedItem)
                listDP.removeItemAt(prodList.selectedIndex);
        }

    ]]>
    

    

    
        
        
    

    

阅读(679) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~