Actionscript 3 滚动时网格项渲染器会出错
我有一个列表,其中Datagrid为Actionscript 3 滚动时网格项渲染器会出错,actionscript-3,apache-flex,datagrid,itemrenderer,Actionscript 3,Apache Flex,Datagrid,Itemrenderer,我有一个列表,其中Datagrid为itemRenderer类似: <s:List id="cList" itemRenderer="views.renderers.DGridItemRenderer" dataProvider="{sList}" useVirtualLayout="false"/> 包含红色/绿色图标的轻微列取决于年龄数据。年龄值应在datagrid中可编辑 如果年龄小于18岁,则为红色或绿色图标 现在,我的问题是,当我
itemRenderer
类似:
<s:List id="cList" itemRenderer="views.renderers.DGridItemRenderer"
dataProvider="{sList}" useVirtualLayout="false"/>
包含红色/绿色图标的轻微列取决于年龄数据。年龄值应在datagrid中可编辑
如果年龄小于18岁,则为红色或绿色图标
现在,我的问题是,当我滚动datagid时,图标会弄乱。图标将显示在任何记录中,无论是否有年龄
首次加载时,所有图标看起来都很好。但当我滚动时,只会弄乱图标并改变它们的位置
我对列表使用了useVirtualLayout=“false”
,对itemrenderer使用了ClipanEnableScrolling=“true”
,但仍然无法解决它
我找到了很多,但没有找到合适的解决方案
编辑:
如果年龄小于18岁,则为红色;如果年龄大于18岁,则为绿色。如果未定义年龄,则为空
我的问题是当我滚动时,空白行也会显示图标。红色图标行将随机变为绿色,绿色变为红色。一切都搞砸了
首先,它显示如下。(没错):
当我滚动datagrid后,它将更改为以下内容。(这是正确的)
您的问题是,由于年龄并不总是设置好,您没有正确地处理项目。如果你的数据总是有一个age
值,你就没事了。实际上,您的代码没有办法清空imgStatus
对象——如果age
为null
或-1
,它只会留下已经存在的图标
将代码更改为以下内容:
if(data.age < 18 && data.age > 0)
{
imgStatus.source = ImageProvider.redIcon;
imgStatus.visible = true;
}
else if(data.age >= 18)
{
imgStatus.source = ImageProvider.greenIcon;
imgStatus.visible = true;
}
else
{
//You could use the following line instead if you have a "clear icon" defined.
//imgStatus.source = ImageProvider.clearIcon;
imgStatus.visible = false;
}
if(data.age<18&&data.age>0)
{
imgStatus.source=ImageProvider.redIcon;
imgStatus.visible=true;
}
否则如果(data.age>=18)
{
imgStatus.source=ImageProvider.greenIcon;
imgStatus.visible=true;
}
其他的
{
//如果定义了“清除图标”,则可以使用以下行。
//imgStatus.source=ImageProvider.clearIcon;
imgStatus.visible=false;
}
如果我理解正确:如果(data.age>=18)用替换else
可能的问题?我读这个问题有困难;我不知道你的意思。imgStatus
图标是否应该出现在每一行?你的代码说它应该,但你的问题暗示它不应该。或者滚动时,某些行的图标颜色是否错误?最后-你能发布一个吗?@user2836288如果它大于18,那么你是对的,否则就不是。我认为你不理解项目渲染器。当你滚动时,你并没有摆脱屏幕上滚动的线条,并创建新的在屏幕上滚动的线条——你是从顶部移动到底部,并在上面设置新的值。因此,如果你没有“else”条款,你不是说“不放任何东西”,你实际上是说“保留已经存在的东西”。我试过了,但无法解决我的问题。我还没有明确的图标定义。我只是不给图像提供源代码,所以它保持空白。我尝试了这个解决方案,以使可见虚假的其他。但还是有问题。我在我的问题中添加了图像,它看起来如何。
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" verticalCenter="0" clipAndEnableScrolling="true">
<fx:Script>
<![CDATA[
override public function prepare(hasBeenRecycled:Boolean):void {
if(data.age < 18 && data.age > 0)
{
imgStatus.source = ImageProvider.redIcon;
}
else if(data.age >= 18)
{
imgStatus.source = ImageProvider.greenIcon;
}
]]>
</fx:Script>
<s:Image id="imgStatus" width="21" height="21" buttonMode="true" horizontalCenter="0" verticalCenter="0" />
</s:GridItemRenderer>
if(data.age < 18 && data.age > 0)
{
imgStatus.source = ImageProvider.redIcon;
imgStatus.visible = true;
}
else if(data.age >= 18)
{
imgStatus.source = ImageProvider.greenIcon;
imgStatus.visible = true;
}
else
{
//You could use the following line instead if you have a "clear icon" defined.
//imgStatus.source = ImageProvider.clearIcon;
imgStatus.visible = false;
}