2011-06-27 35 views
0

我的问题是,当用户单击具有组合框编辑器的DataGrid单元,然后立即单击远离单元格时,该单元格中的文本值将消失。Labelfunction会干扰Combobox项目编辑器

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

为什么labelFunction和item编辑器不能很好地一起玩?

这里的DataGridColumn:

<mx:DataGridColumn 
           headerText="Field Name" 
           dataField="attribId" 
           editorDataField="attributeId" 
           labelFunction="getFieldName"> 

这里是项目编辑

      <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标签功能。

 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时:整数= fieldsGridEmpty.selectedIndex; var attribCombo:ComboBox = ComboBox(fieldsGridEmpty.itemEditorInstance);现在

   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”的有效值:

newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId; 

然而,标签的功能被在此之后执行和item.attribId值为0。这就是'fieldName'的原因是一个空字符串,因为没有匹配。

+0

显示一些代码;这有点困惑。例如,你使用DataGrid列的labelFunction吗?还是为Combobox?你在使用Spark组件还是Halo组件? – JeffryHouser

+0

我已经使用该代码更新了帖子。不幸的是,我无法弄清楚如何让mxml进入代码模式,对不起。但谢谢你看看。 – fumeng

+0

打开的括号/括号按钮将格式化突出显示的代码。 – JeffryHouser

回答

0

我的修复在评论中提到似乎工作。根本的问题是editorDataField属性仅在用户与组合框进行交互时才设置。

我通过在覆盖公共函数集的data()方法中设置它来弥补了这个问题。以这种方式,只要用户触摸它,它就会被设置。