我有一个从DataGrid扩展的CustomDataGrid和从DataGridColumn扩展的CustomDataGridColumn。
CustomDataGridColumn具有Function。
类型的成员变量在我看来,我使用欧芹注入了一个演示模型。
代码如下:
<fx:Declarations>
<spicefactory:Configure/>
</fx:Declarations>
<fx:Script>
[Inject(id="associatedDocumentsPM")]
[Bindable]
public var model:AssociatedDocumentsPM;
</fx:Script>
<customDataGrid:CustomDataGrid id="AssocDocGrid"
width="100%" height="{(documentDataList.length+2)*20}"
doubleClickEnabled="true" enabled="{modeHandler.appEnable}"
dataP="{documentDataList}"
sortableColumns="false">
<customDataGrid:columnList>
<customDataGrid:CustomDataGridColumn
textAlign="left"
dataFieldIdentifier="documentName"
headerText="Document Type"
modifyLabelField="{model.modifyLabelField}"
dataField="documentName"
isNaNZero="true"
showDataTips="true"
editable="false"/>
...more columns here...
</customDataGrid:columnList>
</customDataGrid:CustomDataGrid>
AssociatedDocumentsPM定义了函数,这些函数在列中设置。
一个例子是属性modifyLabelField="{model.modifyLabelField}"
CustomDataGridColumn.myLabelField的类型为Function。 AssociatedDocumentsPM中的myLabelField是一个公共函数。
Parsley Context文件位于上述文件的父文件中,并按如下方式声明PM:
AssocDocPMFactory是一个带有[Factory]装饰的唯一函数的类。
所以问题如下:
当我调试应用程序并检查DataGrid的columnList时,变量modifyLabelField为null。
功能绑定的处理方式与变量不同吗?我正在使用Flex 4.5.1和Parsley 2.4.1
我知道在调用creationComplete之后可能会发生注入,但我认为绑定可以解决这个问题。
我感觉模型 - PM - 在很久之后才为空,并且不会触发函数绑定。
我也尝试使用FastInject,但无济于事。
这是函数指针和Flex绑定的问题吗?
答案 0 :(得分:0)
不,不是。如果您有这些疑问,快速设置一个简单的隔离测试情况来验证您的假设总是一个好主意。我创建了以下内容来测试你的:
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
creationComplete="onCreationComplete()" >
<fx:Script>
<![CDATA[
private function onCreationComplete():void {
test = function(item:*):String {
return "AAA";
}
}
[Bindable]
private var test:Function;
]]>
</fx:Script>
<s:List labelFunction="{test}">
<s:dataProvider>
<s:ArrayList>
<fx:String>A</fx:String>
<fx:String>B</fx:String>
<fx:String>C</fx:String>
</s:ArrayList>
</s:dataProvider>
</s:List>
</s:Application>
如果test
函数变量被声明为Bindable
,您将看到3次“AAA”。如果您删除Bindable
元数据,则会看到“A”,“B”,“C”。
所以明确绑定也适用于函数指针(你必须在其他地方寻找你的nullpointer)。