Flex Datagrid 中的动态 Spark DropDownList ItemRenderer

发布于 2024-09-29 15:36:26 字数 4702 浏览 4 评论 0原文

我有一个数据网格,其中包含需要获取动态数据的 Spark 下拉列表。数据网格使用单独的数据提供程序。

当我在 ItemRenderer 中使用静态 ArrayCollection 时,它可以工作(请参见清单 1)。

但是,当我使用 Swiz 调解“列表完成”事件来加载 ArrayCollection 时,下拉列表不会显示新数据(请参见清单 2)。

使用调试器,我检查了下拉列表 ItemRenderer 并确认新数据正在加载到 ArrayCollection 中。新数据不会显示在 UI 控件中。我尝试过 invalidateProperties() + validateNow() 并在控件和渲染器(this)上调度事件,但似乎没有什么能让新数据出现在数据网格上的控件中。

请帮忙!

清单 1:Datagrid 和静态 ArrayCollection(这有效):

<mx:DataGrid x="10" y="25" width="98%" id="dgInventory" paddingLeft="25" paddingRight="25" paddingTop="25" paddingBottom="25" 
                     editable="true"
                     itemClick="dgInventory_itemClickHandler(event)" dataProvider="{acInventory}"
                     creationComplete="dgInventory_creationCompleteHandler(event)"
                     height="580">
            <mx:columns>
                <mx:DataGridColumn headerText="Item" dataField="itemName" itemRenderer="components.ItemRendererItem"
                                   rendererIsEditor="true" editorDataField="selection" editable="true"/>
                <mx:DataGridColumn headerText="Quantity Required" dataField="quantityReq" itemRenderer="components.ItemRendererQuantityRequired"
                                   rendererIsEditor="true" editorDataField="selection" editable="true"/>
            </mx:columns>
</mx:DataGrid>

<fx:Script>
    <![CDATA[       

        import mx.collections.ArrayCollection;
        import spark.events.IndexChangeEvent;

        public var selection:int;

        [Bindable]
        protected var acItem:ArrayCollection = new ArrayCollection(
            [   { itemName: "Item1"},
                { itemName: "Item2"},
                { itemName: "Item3"},
            ]);
    //
        protected function dropdownlist1_changeHandler(e:IndexChangeEvent):void
        {
            selection = e.newIndex;
        }

    ]]>
</fx:Script>

<s:DropDownList id="ddlItem" prompt="Select Item" dataProvider="{acItem}" labelField="itemName"
                selectedIndex="{int(dataGridListData.label)}"
                change="dropdownlist1_changeHandler(event)"
                width="80%" top="5" bottom="5" left="5" right="5"/>

清单 2:动态 ArrayCollection(不起作用):

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                          xmlns:s="library://ns.adobe.com/flex/spark" 
                          xmlns:mx="library://ns.adobe.com/flex/mx" 
                          focusEnabled="true">

    <fx:Script>
        <![CDATA[       
            import event.ItemEvent;

            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            public var selection:int;
        //
            [Bindable]
            protected var acItem:ArrayCollection = new ArrayCollection();
        //
            protected function dropdownlist1_changeHandler(e:IndexChangeEvent):void
            {
                selection = e.newIndex;
            }
        //
            protected function ddlItem_creationCompleteHandler(event:FlexEvent):void
            {
                var eve : ItemEvent = new ItemEvent( ItemEvent.LIST_ITEM_REQUESTED );
                dispatchEvent( eve );
            }
        //
            [Mediate( event="ItemEvent.LIST_ITEM_COMPLETE", properties="acItem" )]
            public function refreshness( _acItem : ArrayCollection ):void
            {
                acItem.removeAll();

                var len:int = _acItem.length;

                if (len > 0)
                {
                    for (var i:int=0; i < len; i++)
                    {
                        var newItem:Object = new Object;
                        newItem["itemName"] = _acItem[i].itemName;
                        acItem.addItem(newItem);
                    }
                }
                this.invalidateProperties();
                this.validateNow();
                //dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
            }

        ]]>
    </fx:Script>

    <s:DropDownList id="ddlItem" prompt="Select Item" dataProvider="{acItem}" labelField="itemName"
                    selectedIndex="{int(dataGridListData.label)}"
                    creationComplete="ddlItem_creationCompleteHandler(event)"
                    change="dropdownlist1_changeHandler(event)"
                    width="80%" top="5" bottom="5" left="5" right="5"/>
</s:MXDataGridItemRenderer>

I have a datagrid which contains a Spark dropdownlist that needs to obtain dynamic data. The datagrid uses a separate dataProvider.

When I use a static ArrayCollection within my ItemRenderer, it works (please see listing 1).

However, when I use Swiz to mediate a 'list complete' event to load the ArrayCollection, the dropdownlist does not show the new data (please see listing 2).

Using the debugger, I inspected the dropdownlist ItemRenderer and have confirmed the new data is being loaded into the ArrayCollection. The new data is not shown in the UI control. I have tried invalidateProperties() + validateNow() and dispatching events on both the control and the renderer (this), but nothing seems to make the new data appear in the control on the datagrid.

Please help !!!

Listing 1: Datagrid and static ArrayCollection (this works):

<mx:DataGrid x="10" y="25" width="98%" id="dgInventory" paddingLeft="25" paddingRight="25" paddingTop="25" paddingBottom="25" 
                     editable="true"
                     itemClick="dgInventory_itemClickHandler(event)" dataProvider="{acInventory}"
                     creationComplete="dgInventory_creationCompleteHandler(event)"
                     height="580">
            <mx:columns>
                <mx:DataGridColumn headerText="Item" dataField="itemName" itemRenderer="components.ItemRendererItem"
                                   rendererIsEditor="true" editorDataField="selection" editable="true"/>
                <mx:DataGridColumn headerText="Quantity Required" dataField="quantityReq" itemRenderer="components.ItemRendererQuantityRequired"
                                   rendererIsEditor="true" editorDataField="selection" editable="true"/>
            </mx:columns>
</mx:DataGrid>

<fx:Script>
    <![CDATA[       

        import mx.collections.ArrayCollection;
        import spark.events.IndexChangeEvent;

        public var selection:int;

        [Bindable]
        protected var acItem:ArrayCollection = new ArrayCollection(
            [   { itemName: "Item1"},
                { itemName: "Item2"},
                { itemName: "Item3"},
            ]);
    //
        protected function dropdownlist1_changeHandler(e:IndexChangeEvent):void
        {
            selection = e.newIndex;
        }

    ]]>
</fx:Script>

<s:DropDownList id="ddlItem" prompt="Select Item" dataProvider="{acItem}" labelField="itemName"
                selectedIndex="{int(dataGridListData.label)}"
                change="dropdownlist1_changeHandler(event)"
                width="80%" top="5" bottom="5" left="5" right="5"/>

Listing 2: Dynamic ArrayCollection (does not work):

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                          xmlns:s="library://ns.adobe.com/flex/spark" 
                          xmlns:mx="library://ns.adobe.com/flex/mx" 
                          focusEnabled="true">

    <fx:Script>
        <![CDATA[       
            import event.ItemEvent;

            import mx.collections.ArrayCollection;
            import mx.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            public var selection:int;
        //
            [Bindable]
            protected var acItem:ArrayCollection = new ArrayCollection();
        //
            protected function dropdownlist1_changeHandler(e:IndexChangeEvent):void
            {
                selection = e.newIndex;
            }
        //
            protected function ddlItem_creationCompleteHandler(event:FlexEvent):void
            {
                var eve : ItemEvent = new ItemEvent( ItemEvent.LIST_ITEM_REQUESTED );
                dispatchEvent( eve );
            }
        //
            [Mediate( event="ItemEvent.LIST_ITEM_COMPLETE", properties="acItem" )]
            public function refreshness( _acItem : ArrayCollection ):void
            {
                acItem.removeAll();

                var len:int = _acItem.length;

                if (len > 0)
                {
                    for (var i:int=0; i < len; i++)
                    {
                        var newItem:Object = new Object;
                        newItem["itemName"] = _acItem[i].itemName;
                        acItem.addItem(newItem);
                    }
                }
                this.invalidateProperties();
                this.validateNow();
                //dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
            }

        ]]>
    </fx:Script>

    <s:DropDownList id="ddlItem" prompt="Select Item" dataProvider="{acItem}" labelField="itemName"
                    selectedIndex="{int(dataGridListData.label)}"
                    creationComplete="ddlItem_creationCompleteHandler(event)"
                    change="dropdownlist1_changeHandler(event)"
                    width="80%" top="5" bottom="5" left="5" right="5"/>
</s:MXDataGridItemRenderer>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

心的位置 2024-10-06 15:36:26

重新阅读 Peter Ent 的 ItemRenderer 系列后,发现这非常简单。

我扩展了 DataGrid 以具有我需要的 ArrayCollection 属性,然后将其添加到我的渲染器中:

[Bindable]
            protected var acItem:ArrayCollection = new ArrayCollection();
        //
            override public function set data( value:Object ) : void
            {
                super.data = value;
                acItem = (listData.owner as MyDataGrid).itemList; // get the data from the renderer's container (by extending it to add a property, if necessary)
            }

After re-reading Peter Ent's ItemRenderer series, this turned out to be quite simple.

I extended DataGrid to have the ArrayCollection property I needed, then added this to my renderer:

[Bindable]
            protected var acItem:ArrayCollection = new ArrayCollection();
        //
            override public function set data( value:Object ) : void
            {
                super.data = value;
                acItem = (listData.owner as MyDataGrid).itemList; // get the data from the renderer's container (by extending it to add a property, if necessary)
            }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文