Labelfunction 干扰 Combobox 项编辑器
我的问题是,当用户单击具有组合框编辑器的数据网格单元格,然后立即单击远离该单元格时,该单元格中的文本值就会消失。
我在数据网格上有一个 itemEditEnd 处理程序,它显示了我用作 editorDataField 的属性的值。但该网格列上的 labelFunction(在 itemEditEnd 处理程序之后调用)将其视为零。
为什么 labelFunction 和项目编辑器不能很好地协同工作?
这是 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;
}
以下是在 Datagrid 的 itemEditEndHandler 中执行的代码:
var rowCount:int = 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”是空字符串的原因,因为没有匹配项。
My issue is that when a user clicks a datagrid cell that has a combobox editor and then immediately clicks away from the cell, the text value in that cell disappears.
I have an itemEditEnd handler on the datagrid and it shows the value of the property I use as the editorDataField just fine. But the labelFunction (which gets called after the itemEditEnd handler) on that grid column sees it as zero.
Why aren't the labelFunction and item editor playing together nicely?
Here is the DataGridColumn:
<mx:DataGridColumn
headerText="Field Name"
dataField="attribId"
editorDataField="attributeId"
labelFunction="getFieldName">
Here is the Item editor
<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>
and here is the label function for the 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;
}
And here is the code executed in the itemEditEndHandler for the Datagrid:
var rowCount:int = 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;
}
Now, the item edit handler shows a valid value for 'attribId':
newFieldsDp[ rowCount ].attribId = attribCombo.selectedItem.attribId;
However, the label function gets executed after this and the value for item.attribId is 0. And that's the reason 'fieldName' is an empty String, because there's no match.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在评论中提到的修复似乎有效。根本问题是 editorDataField 属性仅在用户与组合框交互时设置。
我通过在覆盖公共函数集 data() 方法中设置它来解决这个问题。以这种方式,一旦用户触摸它,它就被设置。
My fix mentioned in the comments seems to work. The underlying problem is that the editorDataField property was only set when the user interacted with the combobox.
I remedied that problem by setting it in the override public function set data() method. In this manner, as soon as a user touches it, it is set.