组合框/数据网格排序器

发布于 2024-10-12 14:30:16 字数 2758 浏览 2 评论 0原文

我正在尝试将来自 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难如初 2024-10-19 14:30:16

在 Flex 4 中,似乎只有 MX 组件可以拥有原始数据对象作为其数据提供者。 Spark 组件需要实际的集合。

这来自 Adob​​e 关于 Flex 4 中数据提供程序的文档:

对于 Spark 控件,您不能使用
原始对象作为值
控件的数据提供者。你必须
指定一个实现的对象
IList接口。类
实现 IList include
ArrayCollection、ArrayList 和
XMLList集合

我将您的 arr 包装在 ArrayCollection 中,并编译了所有内容:

[Bindable]
private var arr:ArrayCollection = new ArrayCollection([ "time", "teamA", "teamB", "status" ]);

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:

For Spark controls, you cannot use a
raw object as the value of the
control’s data provider. You must
specify an object that implements the
IList interface. Classes that
implement IList include
ArrayCollection, ArrayList, and
XMLListCollection

I wrapped your arr in an ArrayCollection, and everything compiled:

[Bindable]
private var arr:ArrayCollection = new ArrayCollection([ "time", "teamA", "teamB", "status" ]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文