DataGrid行上的StackOverflowError在NumericStepper中的特定限制 [英] StackOverflowError on DataGrid row specific limits in a NumericStepper

查看:191
本文介绍了DataGrid行上的StackOverflowError在NumericStepper中的特定限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格与NumericStepper作为其中一列的项目编辑器。数字步进器应该从每行的数据中获取最大值和最小值。我的MXML是这样的:

 < mx:DataGrid x =0y =45width =272 height =525dataProvider ={dp}variableRowHeight =trueeditable =trueid =equipmentDGverticalAlign =middle> 
< mx:columns>
< mx:itemEditor>
< fx:Component>
< / 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]
在mx.controls :: NumericStepper / set data()[E:\dev\4.x\frameworks\projects \framework\src\mx\controls\NumericStepper.as:629]
在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 /对话框/ TentInfo.mxml:267]
at Function / http://adobe.com/AS3/2006/builtin :: apply()
在mx.binding :: PropertyWatcher / updateProperty()在函数/ http:// adobe上输入
。 com / AS3 / 2006 / builtin :: apply()
在mx.binding :: Watcher / wrapUpdate()[E:\dev\4.x\frameworks\projects\framework\src \ mx\binding\Watcher.as:192)
在mx.binding :: PropertyWatcher / eventHandler()[E:\dev\4.x\frameworks\projects\framework\\ \\ src\mx\binding\PropertyWatcher.as:375]

有什么想法?
<看起来像 minimum 和< >数据导致一个infinit循环。但是,您不需要绑定来更改DataGrid中每行的这两个值。重写 data 的setter将会有效。请看下面的例子:

 <?xml version =1.0encoding =utf-8?> 
xmlns:mx =library://ns.adobe.com/flex/mxminWidth =955minHeight =600
xmlns:local =*>
< fx:Script>
<![CDATA [
import mx.collections.ArrayCollection;
$ b $ [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>

editable =trueid =equipmentDGverticalAlign =middle>
< mx:columns>
width =128dataField =nameeditable =false/>
< mx:DataGridColumn headerText =AntalheaderStyleName =gridheaderwidth =40
dataField =antaleditorDataField =valueeditable =true>
< mx:itemEditor>
< fx:Component>
< mx:NumericStepper stepSize =1width =35height =20>
< fx:Script>
<![CDATA [
覆盖公共函数集数据(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>

如果字段 minNo maxNo 存在,因为setter被调用的频率很高,大多数情况下不是预期的对象。 ..


I have a DataGrid with a NumericStepper as the item editor for one of the columns. The numeric stepper is supposed to get its max an min values from the data for each row. My MXML is like this:

<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>

The problem is that once I run the application and click the cell, I get a StackOverflowError after a bunch of other errors. The last lines of the stack trace I get (before they start repeating) is:

    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]

Any ideas?

解决方案

Well, it looks like binding minimum and maximum to data results in an infinit loop. However, you don't need binding to change those two values for each row in your DataGrid. Overriding the setter for data will do the trick. See the following example:

<?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>

There are explicit checks if the fields minNo and maxNo exist since somehow the setter gets called quite often and most of the time the value is not the expected object...

这篇关于DataGrid行上的StackOverflowError在NumericStepper中的特定限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆