我不确定我做错了什么,所以也许有人可以向我解释。
我有一个amfphp发回的对象数组,它看起来像这样:
(Object)#0
content = (Array)#1
[0] (Object)#2
config = "1"
id = "3"
param = "3"
title = "categorypreview"
[1] (Object)#3
config = "0"
id = "1"
param = "-1"
title = "highestdisplay"
[2] (Object)#4
config = "0"
id = "8"
param = "-1"
title = "featured"
header = (Array)#9
[0] (Object)#10
config = "1"
id = "9"
param = "5"
title = "categorymenu"
[1] (Object)#11
config = "1"
id = "6"
param = "1"
title = "adzones"
我使用的mxml是:
<s:List id="headerList" y="52" left="10" width="200" height="150">
<s:layout>
<s:HorizontalLayout/>
</s:layout>
</s:List>
<mx:DataGrid id="mydatagrid" x="10" y="214">
<mx:columns>
<mx:DataGridColumn headerText="Column 1" dataField="title"/>
<mx:DataGridColumn headerText="Column 2" dataField="param"/>
</mx:columns>
</mx:DataGrid>
动作脚本是:
protected function getLayoutResultHandler(event:ResultEvent):void
{
mydatagrid.dataProvider = event.result.header;
headerList.dataProvider = event.result.header;
}
数据网格只是用于测试。我遇到的问题是datagrid填充了header数组的值,但是list给出了一个错误:
类型强制失败:无法将[] @ dcc5629转换为mx.collections.IList
我做错了什么?
答案 0 :(得分:2)
我明白了!!
这是我必须做的,在动作中我修改了我的功能:
protected function getLayoutResultHandler(event:ResultEvent):void
{
var header:ArrayCollection = new ArrayCollection(event.result.header);
headerList.dataProvider = header;
mydatagrid.dataProvider = header;
}
现在一切正常。
答案 1 :(得分:0)
尝试将event.result.header
视为某种集合。我最好的猜测是,你的amfphp调用返回的数据不会被转换为数据类型而你的List
不知道如何处理它。
protected function getLayoutResultHandler(event:ResultEvent):void
{
mydatagrid.dataProvider = event.result.header as ArrayCollection;
headerList.dataProvider = event.result.header as ArrayCollection;
}