flex-----dataProvider

mx:XMLListCollection 包含多个XMLList
mx:ArrayCollection 包含多个mx:Array
这两个不是包含关系,mx:XMLListCollection和mx:ArrayCollection 是集合类,相对XMLList和Array是包装关系,有点像JAVA里的int和Integer的关系
Array就是数组,与JAVA不一样的地方时,里面的元素类型不需要一致,每一个元素都可以是任意类型;
XMLList看名字就知道了,是一个XML的list,由多个XML组成,与Array比较像,只是元素是XML


 1          dataProvider="{cards}"

            [Bindable]  
            public var cards:ArrayCollection = new ArrayCollection(  
                [ {label:"Visa", data:1},   
                  {label:"MasterCard", data:2},   
                  {label:"American Express", data:3} ]);
或者: cards.addItem({label:"Visa", data:1});
   
2。     dataProvider="{mystates.state}" 

   <mx:Model id="mystates">  
      <states>  
        <state label="Alabama" data="AL"/>  
        <state label="Alaska" data="AK"/>  
        <state label="Arizona" data="AZ"/>  
        <state label="Arkansas" data="AR"/>  
        <state label="California" data="CA"/>  
        <state label="Colorado" data="CO"/>  
        <state label="Connecticut" data="CT"/>  
      </states>  
    </mx:Model>    
                 
3。dataProvider="{treeData}"
  <mx:XMLList id="treeData">  
        <node label="Mail Box">  
            <node label="Inbox">  
                <node label="Marketing"/>  
                <node label="Product Management"/>  
                <node label="Personal"/>  
            </node>  
            <node label="Outbox">  
                <node label="Professional"/>  
                <node label="Personal"/>  
            </node>  
            <node label="Spam"/>  
            <node label="Sent"/>  
        </node>     
    </mx:XMLList>                  
 4。内嵌到list中
  <mx:HorizontalList id="CameraSelection" height="250" columnCount="3" columnWidth="125">  
 //这里的数据提供者也可以用json  ,这里是用的标签的形式  
            <mx:dataProvider>  
                <mx:Array>  //比List中的dataProvider多了一个mx:Array
                    <mx:Object label="Nokia 6630" icon="{phone1}"/>  
                    <mx:Object label="Nokia 6680" icon="{phone2}"/>  
                    <mx:Object label="Nokia 7610" icon="{phone3}"/>  
                   <mx:Object label="Nokia 7610" icon="{phone4}"/>  
  
                </mx:Array>  
            </mx:dataProvider>  
        </mx:HorizontalList>   
        [Bindable]  
             [Embed(source="../assets/nokia6630.png")]  
             public var phone1:Class; 
             
 5。 
   <mx:List id="myList" variableRowHeight="true"   
            height="180" width="250"   
            backgroundColor="white"   
            initialize="initCellEditor();"//渲染器在这里通过as代码指定的 >   
        //这里的dataProvider完全可以写在上面的属性里面哈  
        <mx:dataProvider>  
            <mx:Object label="Alaska"   
                data="Juneau"   
                webPage="http://www.state.ak.us/"/>  
            <mx:Object label="Alabama"   
                data="Montgomery"   
                webPage="http://www.alabama.gov/" />  
            <mx:Object label="Arkansas"   
                data="Little Rock"   
                webPage="http://www.state.ar.us/"/>                    
        </mx:dataProvider>  
    </mx:List>   
    
6. <mx:DataGrid id="dataGrid"
            dataProvider="{arrColl}" .../>
            
     <mx:ArrayCollection id="arrColl">
        <mx:source>
            <mx:Array>
                <mx:Object label="中国" score="1" />
                <mx:Object label="美国" score="0" />
                <mx:Object label="法国" score="0" />
                <mx:Object label="德国" score="0" />
                <mx:Object label="俄罗斯" score="0" />
                <mx:Object label="日本" score="0" />
                <mx:Object label="意大利" score="0" />
                <mx:Object label="捷克" score="1" />
                <mx:Object label="西班牙" score="0" />
                <mx:Object label="澳大利亚" score="0" />
                <mx:Object label="韩国" score="0" />
                <mx:Object label="肯尼亚" score="0" />
            </mx:Array>
        </mx:source>
    </mx:ArrayCollection>      

你可能感兴趣的:(json,xml,Flex)