如何在 Flex4 中重新渲染 DropDownList 的 itemRenderer?

发布于 2024-10-20 02:48:34 字数 2241 浏览 2 评论 0原文

我创建了一个自定义 ComboCheck,它扩展了 Spark DropDownList,它是复选框的 DropDownList。在我的 itemRenderer 内部,我有以下代码:

[Bindable]override public function set data (value:Object):void {
    if (value!=null) {
        _data = value;
        item.label = value.label;
        item.group = value.group;
        item.toolTip = value.toolTip;
        item.selected = value.selected;
        item.enabled = value.enabled;
    ...

该代码允许我启用和禁用下拉列表中的各个项目,以便在渲染时,您将无法选择我已禁用的项目。我正在尝试创建这样的功能:用户单击给定类别中的特定项目,这会导致所有其他类别被禁用,直到您取消选择所有内容。

我的问题是,当 DropDownList 启动时,项目已被渲染,因此更改应禁用的每个项目的 enabled 属性不会更改已渲染的项目。如果您向下滚动并向后滚动以重新渲染数据,它就可以正常工作。

有没有办法让 itemRenderer 重新渲染屏幕上的数据,以便刷新并应用此更新?

下面是所选项目的示例代码,它会禁用所有其他项目,然后仅启用您选择的那个。我还有一个 itemDeselect 函数,可以减少 itemCount 并启用所有内容 <代码>

private function itemSelect(evt:Event):void{
            itemCount++;
            var myText:String = '';
            var items:Vector.<Object> = allItems.selectedItems;
            if(itemCount == 1){
                    for each(var obj:Object in allItems.dataProvider){
                        obj.enabled = false;
                    }
            }
            for (var i:String in items) {
                if(items[i].group == "HU"){
                    items[i].enabled = true;
                    huList[items[i].label] = items[i].selected;
                }else if(items[i].group == "ALL"){
                    items[i].enabled = true;
                    allCase = items[i].selected;
                }else{
                    items[i].enabled = true;
                    otherList[items[i].label] = items[i].selected;
                }

            }

            selectionChanged = true;
}

<代码> 这可以工作,但它不会重新渲染,因此除非您向下滚动并向后滚动,否则 obj.enabled=false 不会出现。

编辑:最终解决方案
使用 www.Flextras.com 建议的第三个选项,我使用了 itemUpdated 属性 dataProvider.itemUpdated(obj),因此在

for each(var obj:Object in allItems.dataProvider){
    obj.enabled = false;
    allItems.dataProvider.itemUpdated(obj);
}

内部,这也不会导致下拉列表重置为滚动位置 0

I have created a custom ComboCheck which extends the spark DropDownList that is a DropDownList of checkboxes. Inside of my itemRenderer I have the code:

[Bindable]override public function set data (value:Object):void {
    if (value!=null) {
        _data = value;
        item.label = value.label;
        item.group = value.group;
        item.toolTip = value.toolTip;
        item.selected = value.selected;
        item.enabled = value.enabled;
    ...

This code allows me to enable and disable individual items in the dropdown list so that when it is rendered, you will not be able to select the items I have disabled. I am trying to create the functionality where a user clicks on a specific item that is in a given category which results in all other categories being disabled until you de-select everything.

My issue is that while the DropDownList is up, the items have already been rendered so changing the enabled property on each item that should be disabled doesn't change the items that have already been rendered. If you scroll down and back up to re-render the data it works fine.

Is there a way to have the itemRenderer re-render the data on the screen so that it refreshes and applies this update?

Below is sample code of an item being selected, it disables every other item then enables only the one you have selected. I also have a itemDeselect function that decrements the itemCount and enables everything

private function itemSelect(evt:Event):void{
            itemCount++;
            var myText:String = '';
            var items:Vector.<Object> = allItems.selectedItems;
            if(itemCount == 1){
                    for each(var obj:Object in allItems.dataProvider){
                        obj.enabled = false;
                    }
            }
            for (var i:String in items) {
                if(items[i].group == "HU"){
                    items[i].enabled = true;
                    huList[items[i].label] = items[i].selected;
                }else if(items[i].group == "ALL"){
                    items[i].enabled = true;
                    allCase = items[i].selected;
                }else{
                    items[i].enabled = true;
                    otherList[items[i].label] = items[i].selected;
                }

            }

            selectionChanged = true;
}


This works but again it is not re-rendered so the obj.enabled=false does not appear unless you scroll down and back up.

EDIT: Final Solution
Using the third option suggested by www.Flextras.com I used the itemUpdated property dataProvider.itemUpdated(obj) so inside of the

for each(var obj:Object in allItems.dataProvider){
    obj.enabled = false;
    allItems.dataProvider.itemUpdated(obj);
}

This will also not cause the dropdownlist to reset to scrollPosition 0

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

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

发布评论

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

评论(3

月野兔 2024-10-27 02:48:34

有没有办法让
itemRenderer 重新渲染数据
显示应用此更新?

我有三种方式

1)使列表的dataGroup而不是列表无效。

listInput.dataGroup.invalidateDisplayList();

2) 刷新 dataProvider

(listInput.dataProvider as ArrayCollection).refresh();

3) 当 dataProvider 项更改时,调用集合上的 itemUpdated() 属性。抱歉,没有这方面的代码示例。

在这种情况下,我经常忘记做的一件事是实现渲染器,以便它知道将自己切换回“非活动”状态。因此,在 itemRenderer 的 set data 方法中,请务必添加一个 else 条件,将所有这些值恢复为默认值。

Is there a way to have the
itemRenderer re-render the data that
is shown to apply this update?

I have three ways.

1) invalidate the list's dataGroup instead of the list.

listInput.dataGroup.invalidateDisplayList();

2) Refresh the dataProvider

(listInput.dataProvider as ArrayCollection).refresh();

3) When the dataProvider item changes, invoke the itemUpdated() property on the collection. No code sample for this one, sorry.

The one thing I often forget to do in this situation is implement the renderer so that it knows to switch itself back into the 'non-active' state. So in your set data method of the itemRenderer be sure to add an else condition putting all those values back to some default.

仄言 2024-10-27 02:48:34

我找到了“重新渲染”的方法,只需重写设置数据函数并更新 itemRenderer 中的所有属性:例如,

我有一个 DataGrid,其中有一列带有 itemRenderer,该列为我的 dataProvider 中的每个项目显示不同的背景颜色。

<mx:DataGrid>
  <mx:columns>
    <mx:DataGridColumn itemRenderer="myItemRenderer"/>
  </mx:columns>
</mx:DataGrid>

//myItemRenderer:

override public function set data( value:Object ) : void {
  super.data = value;
  if( value > 0) setStyle("backgroundColor",0xff99ff);
  else setStyle("backgroundColor",0xffffff);
}

仅此而已。

I found the way to "re-render", just override the set data function and update all the properties in the itemRenderer: eg

I have a DataGrid with a column with an itemRenderer that shows a different backgroundColor for each item in my dataProvider.

<mx:DataGrid>
  <mx:columns>
    <mx:DataGridColumn itemRenderer="myItemRenderer"/>
  </mx:columns>
</mx:DataGrid>

//myItemRenderer:

override public function set data( value:Object ) : void {
  super.data = value;
  if( value > 0) setStyle("backgroundColor",0xff99ff);
  else setStyle("backgroundColor",0xffffff);
}

That's all.

高跟鞋的旋律 2024-10-27 02:48:34

您还可以将 dataChange 事件的事件侦听器添加到项目渲染器本身。更改 data 属性后会触发此事件。

<s:ItemRenderer dataChange="updateView(event)">
    <fx:Script>
        <![CDATA[
            protected function updateView(event:Event):void{
                //update logic
            }
        ]]>
    </fx:Script>
</s:ItemRenderer>

You can also add event listener for dataChange event to the item renderer itself. This event gets fired after data property is changed.

<s:ItemRenderer dataChange="updateView(event)">
    <fx:Script>
        <![CDATA[
            protected function updateView(event:Event):void{
                //update logic
            }
        ]]>
    </fx:Script>
</s:ItemRenderer>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文