【问题标题】:Data Value lose color when Scrolling on Datagrid in Flex 4在 Flex 4 中的 Datagrid 上滚动时数据值失去颜色
【发布时间】:2013-08-05 11:11:13
【问题描述】:

我在滚动数据网格时遇到问题。当我滚动时,我的项目渲染器列正在失去它的价值。 在我的代码中,我更改了 MouseOver 和 MouseOut 上 itemrenderer(标签)的颜色。当我加载数据网格时,这可以正常工作,但是当我向下滚动网格时,某些值的颜色已经改变,就好像在它们上执行了 MouseOver 事件一样。

谁能告诉我这是什么问题?

请查看我的数据网格和 itemrenderer 的代码。请注意,我使用的是灵活的数据网格。

感谢您的宝贵帮助。

        <flxs:columnLevel>
                            <flxs:FlexDataGridColumnLevel>
                                <flxs:columns>
<flxs:FlexDataGridColumn  dataField="testcol" width="118" id="coltest">
<flxs:itemRenderer>

    <fx:Component>
                                                <mx:VBox horizontalAlign="left" paddingLeft="10" verticalAlign="middle">

                                                    <fx:Script>
                                                        <![CDATA[

                                                            import mx.controls.Alert;

                                                            protected function lbl1_clickHandler(event:MouseEvent):void
                                                            {
                                                                //Do Something                      
                                                            }

                                                            protected function lbl1_mouseOverHandler(event:MouseEvent):void
                                                            {
                                                                var dataColor:uint;
                                                                var dataUnderline:String = 'none';
                                                                if (data.payer == 'D'){
                                                                    dataColor = 0x999999;

                                                                }   
                                                                else{
                                                                    dataColor = 0x0DACE0; //color
                        }

                                                            }

                                                            protected function lbl_mouseOutHandler(event:MouseEvent):void
                                                            {
                                                                var dataColor:uint;

                                                                if (data.payer == 'D'){
                                                                    dataColor = 0x999999;
                                                                                                                                    }   
                                                                else{
                                                                    dataColor = 0x000000;

                                                                }
                                                            }
    ]]>
                                                    </fx:Script>
                                                    <mx:Label id="lbl" paddingLeft="10" left="10" fontWeight="normal" mouseOut="lbl_mouseOutHandler(event)" mouseOver="lbl_mouseOverHandler(event)" text="{data.testcol}" click="lbl1_clickHandler(event)"/>
                                                </mx:VBox>  
                                            </fx:Component>
                                        </flxs:itemRenderer>
    </flxs:FlexDataGridColumn>
                    </flxs:columns>
                            </flxs:FlexDataGridColumnLevel>

                        </flxs:columnLevel>

                    </flxs:FlexDataGrid>*

【问题讨论】:

    标签: actionscript-3 apache-flex flex4.5


    【解决方案1】:

    简短回答:您尚未覆盖 itemrenderer 上的“设置数据”,因此它将保留以前的属性。

    Flex 世界中的 Itemrenderer 是可回收的,这意味着即使您的列表中可能有 100 个对象,您的内联 itemrenderer 的实际实例也只有 10-12 个。需要注意的是,当 itemrenderer 填充新数据时,不会重置与数据相关的属性。缺少重置是为什么您的渲染器看起来已经被鼠标悬停,而实际上它们没有。

    标准的解决方案是重写“设置数据”功能,它的功能与听起来完全一样,它在设置数据时执行操作。如果我有类似的问题,我的代码应该是这样的(最好我可以使用上午 9:00 的内存)。

    override public function set data(value:Object):void
    {
        if( value != null )
        { 
           super.data = value'
            dataColor = 0xwhatever-color-non-moused-over-objects-should-have;
        }
    }
    

    这是more information的链接。

    【讨论】:

      猜你喜欢
      • 2014-04-14
      • 2017-05-22
      • 2010-12-26
      • 2012-08-06
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多