0

我做了GridItemRenderer一个错误状态,它在验证data[column.dataField]内容后显示一条红色边框线,除了滚动之外的所有内容......假设顶部项目处于错误状态,其他一切都很好,因为data[column.dataField]它在顶部单元格中只有 null,然后我将条向下滚动一行,当新行即将显示时,我重写的 getCurrentRendererState 被调用,并检查它是否为空,它应该更改为正常状态,但这是事情,在这一点上,data[column.dataField]仍然有顶部的行值,所以在进行验证后data[column.dataField],即使当前单元格显示当前数据,它仍然为空......那么,我怎样才能获得当前单元格值?

<fx:Script>
    <![CDATA[
        import custom_events.DataGridValidationEvent;
        private function creationComplete():void{
            owner.parent.parent.addEventListener(DataGridValidationEvent.VALIDATE,doValidation);
        }
        private function doValidation(e:DataGridValidationEvent):void{
            currentState=data[column.dataField]?"normal":"error";
        }
        override public function get label():String{
            return lblCell.text;
        }
        override public function set label(value:String):void{
            currentState=data?data[column.dataField]?"normal":"error":"normal"
            lblCell.text=value;
        }
        override protected function getCurrentRendererState():String{
            return data?data[column.dataField]?"normal":"error":"normal";
        }
    ]]>
</fx:Script>
<s:states>
    <s:State name="normal"/>
    <s:State name="error"/>
</s:states>
<s:Rect left="1" right="0" top="1" bottom="0" includeIn="error">
    <s:stroke>
        <s:SolidColorStroke color="0xFF001A" weight="1"/>
    </s:stroke>
</s:Rect>
<s:Label id="lblCell" width="100%" height="100%" verticalAlign="middle"
         paddingLeft="5" paddingRight="5" paddingTop="3" maxDisplayedLines="1"
         showTruncationTip="true"/>

4

1 回答 1

1

监听数据更改事件,并在那里进行验证,现在一切都很好。

<fx:Script>
    <![CDATA[
        import custom_events.DataGridValidationEvent;
        private function creationComplete():void{
                owner.parent.parent.addEventListener(DataGridValidationEvent.VALIDATE,doValidation);
                addEventListener(FlexEvent.DATA_CHANGE,setState);
            }
            private function doValidation(e:DataGridValidationEvent):void{
                currentState=data[column.dataField]?"normal":"error";
            }
            private function setState(e:FlexEvent):void{
                currentState=data[column.dataField]?"normal":"error";
            }
            override public function get label():String{
                return lblCell.text;
            }
            override public function set label(value:String):void{
                currentState=data?data[column.dataField]?"normal":"error":"normal"
                lblCell.text=value;
            }
            override protected function getCurrentRendererState():String{
                return currentState;
            }
    ]]>
</fx:Script>
<s:states>
    <s:State name="normal"/>
    <s:State name="error"/>
</s:states>
<s:Rect left="1" right="0" top="1" bottom="0" includeIn="error">
    <s:stroke>
        <s:SolidColorStroke color="0xFF001A" weight="1"/>
    </s:stroke>
</s:Rect>
<s:Label id="lblCell" width="100%" height="100%" verticalAlign="middle"
         paddingLeft="5" paddingRight="5" paddingTop="3" maxDisplayedLines="1"
         showTruncationTip="true"/>
于 2013-02-08T00:08:59.903 回答