首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Labelfunction干扰组合框项编辑器

Labelfunction干扰组合框项编辑器
EN

Stack Overflow用户
提问于 2011-06-27 23:39:21
回答 1查看 1.3K关注 0票数 0

我的问题是,当用户单击具有组合框编辑器的datagrid单元格,然后立即单击离开该单元格时,该单元格中的文本值将消失。

我在datagrid上有一个itemEditEnd处理程序,它可以很好地显示我用作editorDataField的属性的值。但是该网格列上的labelFunction (在itemEditEnd处理程序之后调用)将其视为零。

为什么labelFunction和项目编辑器不能很好地结合在一起?

下面是DataGridColumn:

代码语言:javascript
复制
<mx:DataGridColumn  
                                headerText="Field Name" 
                                dataField="attribId"
                                editorDataField="attributeId"
                                labelFunction="getFieldName">

这是项编辑器

代码语言:javascript
复制
                            <mx:itemEditor>

                                <mx:Component>

                                    <mx:ComboBox 
                                        dataProvider="{this.outerDocument.lendersModel.fileAttributes}"
                                        creationComplete="{outerDocument.selectAttribute();}"
                                        labelField="fileAttribDesc"
                                        change="updateAttribute(event);"
                                        selectedIndex="-1">


                                        <mx:Script>
                                            <![CDATA[                                                   
                                                [Bindable]
                                                public var attributeId:int;
                                                private var fileDetailRecordType:String;

                                                override public function set data( value:Object ):void{
                                                    this.attributeId = value.attribId; // adding this line appears to be the fix. 
                                                    var category:String = value.category;

                                                    this.filterFileAttributes( category );
                                                }

                                                /** Change handler for combobox in Record Type column.  
                                                 */
                                                private function filterFileAttributes( recordType:String ):void{
                                                    this.fileDetailRecordType = recordType;

                                                    this.dataProvider.filterFunction = filterByRecordType;
                                                    this.dataProvider.refresh();
                                                }

                                                /** Filters the file attributes collection based on the record type. 
                                                 */
                                                private function filterByRecordType( item:Object ):String{
                                                    return item.category.match( this.fileDetailRecordType );
                                                }

                                                private function updateAttribute( event:* ):void{ 
                                                    attributeId = event.currentTarget.selectedItem.attribId;
                                                    this.outerDocument.selectedAttributeId = attributeId;
                                                }

                                            ]]>
                                        </mx:Script>

                                    </mx:ComboBox> 

                                </mx:Component>

                            </mx:itemEditor>

这是DataGridColumn的label函数。

代码语言:javascript
复制
        private function getFieldName( item:Object, dgc:DataGridColumn ):String{
            var fieldName:String = '';

            /* At this point the lendersModel.fileAttributes collection is
               filtered based on the record type. We need to remove the filter
               so we can search the entire collection, not just the filtered subset. */
            lendersModel.fileAttributes.filterFunction = refreshFilter;
            lendersModel.fileAttributes.refresh();

            for each( var attrib:FileAttributeDTO in lendersModel.fileAttributes ){
                if( attrib.attribId == item.attribId )
                    fieldName = attrib.fileAttribDesc;
            }

            return fieldName;
        }

下面是在itemEditEndHandler中为Datagrid执行的代码:

var rowCount:int = fieldsGridEmpty.selectedIndex;var属性组合:组合框= ComboBox( fieldsGridEmpty.itemEditorInstance );

代码语言:javascript
复制
                if( rowCount != -1 && attribCombo.selectedItem != null )
                {                                                           
                    newFieldsDp[ rowCount ].fileAttribute.dataType = attribCombo.selectedItem.dataType;                                         
                    newFieldsDp[ rowCount ].fileAttribute.dataLength = attribCombo.selectedItem.dataLength; 
                    newFieldsDp[ rowCount ].fileAttribute.fileAttribDesc = attribCombo.selectedLabel;   
                    newFieldsDp[ rowCount ].dataLength = attribCombo.selectedItem.dataLength;       
                    newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId;   
                }  

现在,项编辑处理程序显示了‘attribId’的有效值:

代码语言:javascript
复制
newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId;

但是,在此之后将执行label函数,并且item.attribId的值为0。这就是'fieldName‘是空字符串的原因,因为没有匹配。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-28 22:42:54

我在评论中提到的修复方法似乎有效。潜在的问题是,只有在用户与组合框交互时才设置editorDataField属性。

我在override public function set data()方法中设置了它,从而解决了这个问题。以这种方式,只要用户触摸它,它就会被设置。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6495363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档