Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 在datagrid-Adobe Flex中编辑时保持当前值_Actionscript 3_Apache Flex_Adobe_Flash Builder - Fatal编程技术网

Actionscript 3 在datagrid-Adobe Flex中编辑时保持当前值

Actionscript 3 在datagrid-Adobe Flex中编辑时保持当前值,actionscript-3,apache-flex,adobe,flash-builder,Actionscript 3,Apache Flex,Adobe,Flash Builder,我有两个datagrid,可以将任何项目从datagrid A拖到datagrid B中。在datagrid B中,我可以编辑值,这些值有最小值和最大值限制。这些值具有货币格式。但是,我有一个问题:当我编辑掉在datagrib中的项目中的值时,该值会自动更改为最小值 正确的方法是在编辑时保留当前值 有什么想法吗 守则: <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="libra

我有两个datagrid,可以将任何项目从datagrid A拖到datagrid B中。在datagrid B中,我可以编辑值,这些值有最小值和最大值限制。这些值具有货币格式。但是,我有一个问题:当我编辑掉在datagrib中的项目中的值时,该值会自动更改为最小值

正确的方法是在编辑时保留当前值

有什么想法吗

守则:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               width="650"
               creationComplete="initApp();">

<fx:Script>
    <![CDATA[
        import mx.collections.ArrayCollection;
        import mx.events.DataGridEvent;

        private function initApp():void {
            dgA.dataProvider = new ArrayCollection([
                {Expense:'Electricity', Value:300, minNo: 100, maxNo: 500},
                {Expense:'Phone', Value:200, minNo: 50, maxNo: 300},
                {Expense:'Contract A', Value:5000, minNo: 4000, maxNo: 6000},
                {Expense:'Contract B', Value:6000, minNo: 4500, maxNo: 8500},
                {Expense:'Contract C', Value:3000, minNo: 2500, maxNo: 3500}
            ]);

            dgB.dataProvider = new ArrayCollection([]);
        }

        private function disableEditing(event:DataGridEvent):void {
            if(event.columnIndex==0)
            {
                event.preventDefault(); 
            }
        }

        protected function LabelFormatter(item:Object, column:DataGridColumn):String
        {
            return MoedaFormatter.format(item.Value);
        }

    ]]>
</fx:Script>

<fx:Declarations>
    <mx:CurrencyFormatter id="MoedaFormatter" precision="2" currencySymbol="R$" alignSymbol="left" decimalSeparatorTo="," decimalSeparatorFrom=","  thousandsSeparatorFrom="." thousandsSeparatorTo="."/>
</fx:Declarations>

<s:HGroup>

    <s:VGroup>
        <s:Label text="Cost 1"/>
        <mx:DataGrid id="dgA"
                     allowMultipleSelection="true" 
                     dragEnabled="true" 
                     dropEnabled="true" 
                     dragMoveEnabled="true">
            <mx:columns>
                <mx:DataGridColumn dataField="Expense"/>
                <mx:DataGridColumn dataField="Value" labelFunction="LabelFormatter"/>
            </mx:columns>    
        </mx:DataGrid>
    </s:VGroup>

    <s:VGroup>
        <s:Label text="Cost 2"/>
        <mx:DataGrid id="dgB"
                     allowMultipleSelection="true" 
                     dragEnabled="true" 
                     dropEnabled="true" 
                     dragMoveEnabled="true"
                     editable="true"
                     itemEditBeginning="disableEditing(event);">
            <mx:columns>
                <mx:DataGridColumn dataField="Expense"/>
                <mx:DataGridColumn dataField="Value" editorDataField="value" labelFunction="LabelFormatter">
                    <mx:itemEditor>
                        <fx:Component>
                            <mx:NumericStepper stepSize="1" width="35" height="20">
                                <fx:Script>
                                    <![CDATA[
                                        override public function set data(value:Object):void
                                        {
                                            super.data = value;

                                            if (value && value.hasOwnProperty("minNo")) {
                                                minimum = value.minNo;
                                            }

                                            if (value && value.hasOwnProperty("maxNo")) {
                                                maximum = value.maxNo;
                                            }
                                        }
                                    ]]>
                                </fx:Script>
                            </mx:NumericStepper>
                        </fx:Component>
                    </mx:itemEditor>
                </mx:DataGridColumn>
            </mx:columns>    
        </mx:DataGrid>
    </s:VGroup>

</s:HGroup>


提前谢谢

从dgA中删除项目时,您会删除包含minNo和maxNo属性的对象,而连接到数据属性更改的脚本会指定项目渲染器的最小和最大属性


因此,只需删除dgB中嵌套的标记或对其进行注释。

在itemeditor中修改set data方法,如下所示

override public function set data(value:Object):void {
     super.data = value;
     if (value && value.hasOwnProperty("Value")) {
        super.value = value.Value;
     }
     if (value && value.hasOwnProperty("minNo")) {
        minimum = value.minNo;
     }

     if (value && value.hasOwnProperty("maxNo")) {
        maximum = value.maxNo;
     }
}

我自己已经测试过了,效果很好

如果我删除了标签,我如何定义极限值?您需要定义它们吗?它们在开始时没有定义,只是在您从dgA中删除项目之后才定义。我感觉到一件事:如果我删除dgB中的labelFunction LabelFormatter,它就可以工作了!所以,问题是这个标签!有什么想法吗?可能是labelFunction和NumericStepper item渲染器之间的冲突,前者将数据转换为一些奇怪的字符串,后者将该字符串视为数字,而将其重置为最小值。您刚才不是解决了这个问题吗?还是你需要全部?要显示的最小值/最大值、NumericStepper和格式化字符串?