删除行时,Flex Custom ItemEditor出现在错误的单元格中

时间:2012-02-28 23:10:37

标签: flex datagrid combobox itemeditor

我有一个带有自定义ItemEditor的数据网格,用于其中一些列。其中一个显示组合框。当用户进行特定选择时,我会在修改后的项目后添加额外的七行。如果用户稍后更改了此组合框选择,则会删除这七行。

我遇到一个问题,在添加七行后,会向数据网格添加一个滚动条。当我更改组合框以删除这7个项目时,它们会被删除,滚动条会消失,但列表中的上一个项目现在会显示组合框而不是当前选定的行。更改组合框会更改预期项目和前一项目的值。

我在添加/删除7项后调用dataprovider上的刷新,因为在这种情况下,datagrid中的其他列也需要更新。

如果在删除7个项目之后但在刷新之前放置断点,则行为将不会重现。否则,我会得到这种奇怪的行为。将刷新放在callLater中无效。我认为这是一个具有约束力的问题,正如Sam DeHaan所提到的那样。

如果是绑定问题,我想使用dataProxy来修复它,如果可能的话。我的数据是XML,当我尝试设置dataProxy.@label =之类的内容时,我收到以下错误:

  

ReferenceError:错误#1081:在Object上找不到属性数据类型,并且没有默认值。       在mx.utils :: ObjectProxy / http://www.adobe.com/2006/actionscript/flash/proxy :: setProperty()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ utils的\ ObjectProxy.as:497]       at Properties.SystemProperties.CustomTypes.EditorsAndRenderers :: SubtypeDatatypeItemEditor / updateValue()[C:\ Users \ blongmore \ Desktop \ Nitrovision \ NVClient Trunk \ Properties \ SystemProperties \ CustomTypes \ EditorsAndRenderers \ SubtypeDatatypeItemEditor.mxml:60]       at Properties.SystemProperties.CustomTypes.EditorsAndRenderers :: SubtypeDatatypeItemEditor / __ SubtypeDatatype_cb_change()[C:\ Users \ blongmore \ Desktop \ Nitrovision \ NVClient Trunk \ Properties \ SystemProperties \ CustomTypes \ EditorsAndRenderers \ SubtypeDatatypeItemEditor.mxml:122]       在flash.events::EventDispatcher/dispatchEventFunction()       at flash.events::EventDispatcher/dispatchEvent()       在mx.core :: UIComponent / dispatchEvent()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:12528]       在mx.controls :: ComboBox / dispatchChangeEvent()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ controls \ ComboBox.as:1888]       在mx.controls :: ComboBox / close()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ controls \ ComboBox.as:1653]       在mx.controls :: ComboBox / dropdown_changeHandler()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ controls \ ComboBox.as:2146]       在flash.events::EventDispatcher/dispatchEventFunction()       at flash.events::EventDispatcher/dispatchEvent()       在mx.core :: UIComponent / dispatchEvent()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ core \ UIComponent.as:12528]       在mx.controls.listClasses :: ListBase / mouseUpHandler()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ controls \ listClasses \ ListBase.as:10263]       at mx.controls :: List / mouseUpHandler()[E:\ dev \ 4.x \ frameworks \ projects \ framework \ src \ mx \ controls \ List.as:2469]

似乎ObjectProxy尝试在Object上设置属性而不包含“@”,因此抛出错误,因为XML对象没有“label”属性,只有“@label”属性。

这是我的ItemEditor代码。只需将dataProxy替换为数据即可避免上述错误。

    <?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
     xmlns:s="library://ns.adobe.com/flex/spark" 
     xmlns:mx="library://ns.adobe.com/flex/mx"
     implements="mx.managers.IFocusManagerComponent">
<fx:Script>
    <![CDATA[
        //IMPORTS REMOVED           
        private var dataProxy:ObjectProxy;


        /**
         * returns the value the data is set to when the cell loses focus.
         */
        public function get value():String{
            if(data.@datatype != ""){
                return StringUtil.trim(String(data.@datatype));
            }
            return "Click to Edit";
        }


        /**
         * Sets the data for the renderer components when the cell receives focus.
         */
        override public function set data(item:Object):void{
            super.data = item;
            dataProxy = new ObjectProxy(data);
            SubtypeDatatype_cb.selectedIndex = Util.getSelIndex(SubtypeDatatype_cb.dataProvider, "data", String(dataProxy.@datatype));
            if(dataProxy.@enabled == "F")
                SubtypeDatatype_cb.enabled = false;
        }


        override public function setFocus():void{
            SubtypeDatatype_cb.setFocus();              
        }


        /**
         * Event listener on the renderer combo box.
         */
        private function updateValue():void{
            var removeChain:Boolean = dataProxy.@datatype == Constants.CHAIN
            var addChain:Boolean = SubtypeDatatype_cb.selectedItem.data == Constants.CHAIN;

            //set the datatype to the newly selected item.
            dataProxy.@datatype = SubtypeDatatype_cb.selectedItem.data;

            var dataList:ListCollectionView = ListCollectionView(ListBase(owner).dataProvider);
            var startIndex:int;
            var i:int;
            if(removeChain){
                startIndex = ListCollectionView(ListBase(owner).dataProvider).getItemIndex(data);
                //Remove the next seven CHAIN items.
                for(i = 0; i < 7; ++i){
                    if(dataList.getItemAt(startIndex + 1).@datatype == Constants.CHAIN){
                        dataList.removeItemAt(startIndex + 1);
                    }else{
                        //SHOULD ALWAYS HIT 7 OF THESE. If Not, we are BROKEN!!!!!
                        GlobalCalls.errorHandler("BAD THINGS HAVE HAPPENED", "ER1000");
                    }
                }
            }
            else if(addChain){
                var baseName = "Subtype"
                var subtypeNumber:int;
                var totalChains:int = 0;
                for(i = 0; i < dataList.getItemIndex(dataProxy); ++i){
                    if(dataList.getItemAt(i).@datatype == Constants.CHAIN){
                        if(totalChains % 8 == 0){
                            subtypeNumber++;
                        }
                        totalChains++;
                    }else if(dataList.getItemAt(i).@datatype != Constants.CHAIN){
                        subtypeNumber++;
                    }
                }
                baseName += (subtypeNumber + 1).toString();
                if(data.@label != ""){
                    baseName = String(data.@label);
                }else{
                    dataProxy.@label = baseName + "_1";
                }
                startIndex = dataList.getItemIndex(dataProxy) + 1;
                for (i = 0; i < 7; ++i){
                    dataList.addItemAt(new XML("<subtype label='" + baseName + "_" + (8 - i) + "' datatype='"+Constants.CHAIN+"' length='1' enabled='F' />"), startIndex);
                }
            }

            //Ensures that the SubtypeLengthItemRenderer is updated ASAP.
            ListCollectionView(ListBase(owner).dataProvider).refresh();
        }

    ]]>
</fx:Script>
<mx:ComboBox id="SubtypeDatatype_cb" width="95%" change="updateValue()" alpha="1" styleName="Dialog" y="2">
    <mx:dataProvider>
        <fx:Object label="Type 1" data="{Constants.TYPE1}"/>
        <fx:Object label="Type 2" data="{Constants.TYPE2}"/>
        <fx:Object label="Type 3" data="{Constants.TYPE3}"/>
        <fx:Object label="Type 4" data="{Constants.TYPE4}"/>
        <fx:Object label="Type 5" data="{Constants.CHAIN}"/>
    </mx:dataProvider>
</mx:ComboBox>

0 个答案:

没有答案