如何使用HierarchicalData将arraycollection传递给Advancedatagrid?

时间:2009-10-30 09:39:01

标签: php flex datagrid flash

将arraycollection传递给Advance datagrid时出现问题。我的Arraycollection结构如`

private var groupList:ArrayCollection = new ArrayCollection([
 {Country:'India', children:[

     {Country:'Series1', children:[
                               {Matches:'India Test series 1',isEnable:false,id:1,isSelected:true},
                               {Matches:'India Test series 2',isEnable:false,id:2,isSelected:true},
                               {Matches:'India Test series 3',isEnable:false,id:3,isSelected:true}]},
              {Country:'Series2', children:[
                               {Matches:'Australia Test series 1',isEnable:false,id:25,isSelected:true},
                               {Matches:'Australia Test series 2',isEnable:false,id:26,isSelected:true},
                               {Matches:'Australia Test series 3',isEnable:false,id:27,isSelected:true}]}

    ]},
{Country:'Austrila', children:[

    {Country:'Series1', children:[
                               {Matches:'Australia Test series 1',isEnable:false,id:46,isSelected:true},
                               {Matches:'Australia Test series 2',isEnable:false,id:47,isSelected:true},
                               {Matches:'Australia Test series 3',isEnable:false,id:48,isSelected:true}]},
{Country:'Series2', children:[
                               {Matches:'Australia Test series 1',isEnable:false,id:49,isSelected:true},
                               {Matches:'Australia Test series 2',isEnable:false,id:50,isSelected:true},
                               {Matches:'Australia Test series 3',isEnable:false,id:51,isSelected:true}]},
{Country:'Series3', children:[
                               {Matches:'Australia Test series 1',isEnable:false,id:52,isSelected:true},
                               {Matches:'Australia Test series 2',isEnable:false,id:53,isSelected:true},
                               {Matches:'Australia Test series 3',isEnable:false,id:54,isSelected:true}]}

]}

dataProvider="{new HierarchicalData(groupList)}"传递广告它工作正常。它显示了基于国家的树和儿童的两个菜单。但我尝试通过下面的代码动态xml转换为Arraycollection

private function convertXmlToArrayCollection( file:String ):ArrayCollection
   {
    var xml:XMLDocument = new XMLDocument( file );



    //var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();


   var decoder1:SimpleXMLDecoder = new SimpleXMLDecoder(true);


    var data1:Object = decoder1.decodeXML( xml );

    var array1:Array = ArrayUtil.toArray(data1);

    return new ArrayCollection( array1 );
   }

我的xml结构是

 <Country Country="India ">
    <Country Country="Series ">
      <Matches Matches="BIndependiente-Colon" id="701536" isEnable="false" isSelected="true" startDate="2009-10-29 01:30:00" EndDate="2009-10-29 01:30:00"/>
      <Matches Matches="Boca Juniors-Chacarita Juniors" id="701633" isEnable="false" isSelected="true" startDate="2009-10-29 19:00:00" EndDate=""/>
    </Country>
  </Country>

    <Country Country="Australia">
    <Country Country="series">
      <Matches Matches="BIndependiente-Colon" id="701536" isEnable="false" isSelected="true" startDate="2009-10-29 01:30:00" EndDate="2009-10-29 01:30:00"/>
      <Matches Matches="Boca Juniors-Chacarita Juniors" id="701633" isEnable="false" isSelected="true" startDate="2009-10-29 19:00:00" EndDate=""/>
    </Country>
  </Country>

因此,如果我尝试将这种格式的xml代码转换为arryacollection,它会转换数组集合,但是当我将传递给Advance数据网格时,它不会显示任何结果。我错了什么?

groupList1= convertXmlToArrayCollection(string1);
Alert.show(groupList1[0].Country[0].Matches[0].id.toString());// output is =701536 

我在哪里弄错了? Plz请任何人推荐我,我会改变什么?

1 个答案:

答案 0 :(得分:0)

你做了groupList1 [Bindable]吗?当你将它设置为datagrids数据提供者时,它是通过绑定还是只是简单的赋值?

您还尝试在数据网格上调用'invalidateDisplayList()'

您可以尝试的另一个选项是将xml直接设置为dataprovider(不要转换为ArrayCollection)。

希望有所帮助