2010-08-05 80 views
2

我在这里我想要在解析XML象下面这样:问题与Flex中解析XML到DataGrid中

<?xml version="1.0" encoding="utf-8" ?> 
<spearkerslist> 
    <speakers langid="afb" countryid="SA">200000</speakers> 
    <speakers langid="acw" countryid="SA">6000000</speakers> 
    <speakers langid="ars" countryid="SA">8000000</speakers> 
    <speakers langid="arb" countryid="SA">206000000</speakers> 
</spearkerslist> 

通过这个代码,我能够解析参数LANGID和countryid,但我无法将实际值200000,6000000 ......解析到数据网格中。有没有一种方法可以在不更改生成的XML的情况下访问它。

<mx:Script> 
[Bindable] 
private var languagelist:XML = new XML(); 
</mx:Script> 

<mx:DataGrid dataProvider="{languagelist.speakers}"> 
    <mx:columns> 
     <mx:DataGridColumn id="populationCol" dataField="speakers" headerText="Speakers" /> 
     <mx:DataGridColumn id="countryID" dataField="@countryid" headerText="Country Id" /> 
     <mx:DataGridColumn id="LangID" dataField="@langid" headerText="Language Id" /> 
    </mx:columns> 
</mx:DataGrid> 

回答

2

尝试没有dataField

<mx:DataGridColumn id="populationCol" headerText="Speakers" /> 

如果这不起作用,使用labelFunction

<mx:DataGridColumn id="populationCol" headerText="Speakers" 
    labelFunction="dgLabelFunction"/> 

把它定义为:

public function dgLabelFunction(item:Object, col:DataGridColumn):String 
{ 
    return item.text().toString(); 
} 
+0

labelFunction()为我工作! – Saneef 2010-08-05 12:26:43

0

只是一个仅供参考的任何人类似的问题。你也可以指定dataField =“*”来获得相同的结果。

<mx:DataGridColumn id="populationCol" headerText="Speakers" dataField="*"/>