我正在尝试将来自flex3的组合框/数据网格分类器更新为flex4版本,但我不断收到我的新手大脑未处理的错误。 错误是“1067:将类型Array的值隐式强制转换为不相关的类型mx.collections:IList。” 请帮忙
这是我的代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="fnCreationComplete(event)"
>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.collections.Sort;
import mx.collections.SortField;
import mx.events.FlexEvent;
import spark.events.DropDownEvent;
[Bindable]
private var arrColl:ArrayCollection;
[Bindable]
private var arr:Array = [ "time", "teamA", "teamB", "status" ];
private var SelectedFilter:String;
protected function fnCreationComplete(event:FlexEvent):void
{
arrColl = new ArrayCollection();
arrColl.addItem( { time: "30:45", teamA: "Ab", teamB: "B", status: "3'" } );
arrColl.addItem( { time: "20:45", teamA: "Ac", teamB: "C", status: "2'" } );
arrColl.addItem( { time: "19:45", teamA: "Ad", teamB: "B", status: "1'" } );
}
private function fnComboxClosed(e:DropDownEvent):void
{
var tempCol:DataGridColumn = this[ comboBox.selectedItem ] as DataGridColumn;
tempCol.sortDescending = false;
}
private function onComboChange( e:Event ) :void
{
SelectedFilter = e.currentTarget.selectedItem;
var sort:Sort = new Sort();
sort.fields = [ new SortField( SelectedFilter, true ) ];
arrColl.sort = sort;
arrColl.refresh();
}
]]>
</fx:Script>
<mx:DataGrid id="dg" dataProvider="{arrColl}"
rowCount="7" horizontalCenter="0" top="10">
<mx:columns>
<mx:DataGridColumn id="time" headerText="Time" dataField="time"/>
<mx:DataGridColumn id="teamA" headerText="Team A" dataField="teamA"/>
<mx:DataGridColumn id="teamB" headerText="Team B" dataField="teamB"/>
<mx:DataGridColumn id="status" headerText="Status" dataField="status"/>
</mx:columns>
</mx:DataGrid>
<s:ComboBox id="comboBox"
dataProvider="{arr}"
close="fnComboxClosed(event)"
change="onComboChange(event)" horizontalCenter="0" top="209"/>
</s:Application>
答案 0 :(得分:2)
在Flex 4中,似乎only MX components可以将原始数据对象作为其数据提供者。 Spark组件需要实际的集合。
这是Adobe关于Flex 4中数据提供者的文档:
对于Spark控件,您不能使用 原始对象作为值 控制的数据提供者。你必须 指定一个实现该对象的对象 IList界面。那个类 实现IList包含 ArrayCollection,ArrayList和 的XMLListCollection
我将你的arr
包装在一个ArrayCollection中,并编译了所有内容:
[Bindable]
private var arr:ArrayCollection = new ArrayCollection([ "time", "teamA", "teamB", "status" ]);