组合框/数据网格排序器
我正在尝试将来自 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>
I'm trying to update a combobox/datagrid sorter that came from flex3 to a flex4 version but I keep getting an error that my newbie brain is not processing.
The error is "1067: Implicit coercion of a value of type Array to an unrelated type mx.collections:IList."
Please help
Here is my code:
<?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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Flex 4 中,似乎只有 MX 组件可以拥有原始数据对象作为其数据提供者。 Spark 组件需要实际的集合。
这来自 Adobe 关于 Flex 4 中数据提供程序的文档:
我将您的 arr 包装在 ArrayCollection 中,并编译了所有内容:
In Flex 4, it seems only MX components can have raw data objects as their data providers. Spark components require actual collections.
This from Adobe's docs on data providers in Flex 4:
I wrapped your
arr
in an ArrayCollection, and everything compiled: