2011-06-27 39 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()方法中設置它來彌補了這個問題。以這種方式,只要用戶觸摸它,它就會被設置。