AS3:用于DataGrid的基于XML的DataProvider使列无序

问题描述

|| 我通过向AS3传递以下XML来创建一个名为\'dataProvider \'的DataProvider:
<GameInfo>
  <item>
    <attribute>name</attribute>
    <info>default0</info>
  </item>
  <item>
    <attribute>type</attribute>
    <info>Abe</info>
  </item>
  <item>
    <attribute>health</attribute>
    <info>100</info>
  </item>
  <item>
    <attribute>frame</attribute>
    <info>1</info>
  </item>
  <item>
    <attribute>through</attribute>
    <info>true</info>
  </item>
  <item>
    <attribute>time</attribute>
    <info>2</info>
  </item>
</GameInfo>
然后,我将DataProvider分配给使用以下代码扩展DataGrid的对象:
this.dataProvider = dataProvider;
我的问题是,生成的DataGrid将信息字段放在第一列中,而将属性字段放在第二列中。我假设索引0处的xml元素将放在列0中,但是它们被切换了。 我知道我可以简单地进入并切换列,但是该解决方案似乎有点破烂,我想弄清楚我的潜在错误是什么。 如果问题不清楚,请告诉我。     

解决方法

        可能还有另一种方法,但这是我设置列的方式 dataGrid具有column属性。 将数组绑定到该属性。 这是DataGridColumn的数组 按需要按入标题 确保在数据提供者数据更改之前创建了列
[Bindable]
public var aColumns:Array;


var myAttribute:DataGridColumn = new DataGridColumn( );
myAttribute.dataField = \'attribute\';
myAttribute.visible = true;

// measure the width of the text to make it pretty
var label:TextField = new TextField();
label.text = \'attribute\';
var metrics:TextLineMetrics = label.getLineMetrics(0);
myAttribute.width = metrics.width + 30;



var myInfo:DataGridColumn = new DataGridColumn( );
myInfo.dataField = \'info\';
myInfo.visible = true;

// measure the width of the text to make it pretty
var label:TextField = new TextField();
label.text = \'info\';
var metrics:TextLineMetrics = label.getLineMetrics(0);
myInfo.width = metrics.width + 30;


aColumns.push( myAttribute);
aColumns.push( myInfo);

this.columns = aColumns;
    

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...