apache-flex NumericStepper中DataGrid行特定限制上的StackOverflowError

2ledvvac  于 2022-11-01  发布在  Apache
关注(0)|答案(1)|浏览(202)

我有一个DataGrid,其中一个列的项目编辑器是NumericStepper。数字步进器应该从每一行的数据中获取其最大值和最小值。我的MXML如下所示:

<mx:DataGrid x="0" y="45" width="272" height="525" dataProvider="{dp}" variableRowHeight="true" editable="true" id="equipmentDG" verticalAlign="middle">                
    <mx:columns>                                        
        <mx:DataGridColumn headerText="Benämning" headerStyleName="gridheader" fontSize="12" width="128" dataField="name" editable="false"/>
        <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40" dataField="antal" editorDataField="value" editable="true">
            <mx:itemEditor>
                <fx:Component>
                    <mx:NumericStepper minimum="data.minNo" maximum="data.maxNo" stepSize="1" width="35" height="20"></mx:NumericStepper>               
                </fx:Component>
            </mx:itemEditor>
        </mx:DataGridColumn>
    </mx:columns>
</mx:DataGrid>

问题是,当我运行应用程序并单击单元格时,在一系列其他错误之后,我得到了一个StackOverflowError。我得到的堆栈跟踪的最后几行(在它们开始重复之前)是:

at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:12528]
    at mx.controls::NumericStepper/set data()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\NumericStepper.as:629]
    at mx.controls::NumericStepper/get data()[E:\dev\4.x\frameworks\projects\framework\src\mx\controls\NumericStepper.as:611]
    at Function/()[/Users/lisbeth/Documents/Development/Typkatalog/DevelopmentBranch/src/planeringsverktyg/dialogs/TentInfo.mxml:267]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.binding::PropertyWatcher/updateProperty()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\PropertyWatcher.as:334]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at mx.binding::Watcher/wrapUpdate()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\Watcher.as:192]
    at mx.binding::PropertyWatcher/eventHandler()[E:\dev\4.x\frameworks\projects\framework\src\mx\binding\PropertyWatcher.as:375]

有什么想法吗?

eoxn13cs

eoxn13cs1#

看起来,将minimummaximum绑定到数据会导致无限循环。但是,您不需要绑定来更改DataGrid中每一行的这两个值。覆盖data的setter就可以实现这一点。请参见以下示例:

<?xml version="1.0" encoding="utf-8"?>
<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" minWidth="955" minHeight="600"
               xmlns:local="*">
    <fx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;

            [Bindable]
            private var dp:ArrayCollection = new ArrayCollection([
                {name: "Name 1", antal: 1, minNo: 1, maxNo: 5},
                {name: "Name 2", antal: 2, minNo: 1, maxNo: 6},
                {name: "Name 3", antal: 3, minNo: 1, maxNo: 7}
                ]);
        ]]>
    </fx:Script>

    <mx:DataGrid x="0" y="45" width="272" height="525" dataProvider="{dp}" variableRowHeight="true"
                 editable="true" id="equipmentDG" verticalAlign="middle">
        <mx:columns>
            <mx:DataGridColumn headerText="Benämning" headerStyleName="gridheader" fontSize="12"
                               width="128" dataField="name" editable="false"/>
            <mx:DataGridColumn headerText="Antal" headerStyleName="gridheader" width="40"
                               dataField="antal" editorDataField="value" editable="true">
                <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:Application>

如果字段minNomaxNo存在,则会进行显式检查,因为不知何故,setter经常被调用,并且大多数情况下value不是预期的对象...

相关问题