我有以下itemrenderer
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer 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">
<s:Label id="lblData" top="0" left="0" right="0" bottom="0" text="{listData.label}" />
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
override public function set data(value:Object):void
{
if(value != null)
{
super.data = value;
if(value.age >30 )
lblData.setStyle("backgroundColor","red");
else
lblData.setStyle("backgroundColor","green");
}
//super.invalidateDisplayList();
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth,unscaledHeight);
if(super.data)
{
}
}
]]>
</fx:Script>
</s:MXAdvancedDataGridItemRenderer>
我的问题是上面的逻辑应该在updtaeDisplayList中还是保留在set data()本身中。 两者的输出都很糟糕。如果我们从生命周期的角度考虑它,那么性能影响差异是什么。(繁重的计算应该推向帧渲染的末尾)
答案 0 :(得分:2)
按照您的方式,我宁愿使用invalidateProperties()
和commintProperties()
。但是如何使用数据绑定?
<?xml version="1.0" encoding="utf-8"?>
<s:MXAdvancedDataGridItemRenderer 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">
<s:Label top="0" left="0" right="0" bottom="0" text="{listData.label}" backgroundColor="{data.age > 30 ? `red` : `green`}" />
</s:MXAdvancedDataGridItemRenderer>