0

我有一个从 DataGrid 扩展的 CustomDataGrid 和一个从 DataGridColumn 扩展的 CustomDataGridColumn。

CustomDataGridColumn 具有函数类型的成员变量。

在我看来,我使用 parsley 注入了一个演示模型。

代码如下:

<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 是函数类型。AssociatedDocumentsPM 中的 myLabelField 是一个公共函数。

Parsley Context 文件位于上述文件的父级中,并声明 PM 如下:

AssocDocPMFactory 是一个具有用 [Factory] ​​装饰的唯一函数的类。

所以问题如下:

当我调试应用程序并检查 DataGrid 的 columnList 时,变量 modifyLabelField 为空。

函数绑定与变量的处理方式不同吗?我正在使用 Flex 4.5.1 和 Parsley 2.4.1

我知道在调用 creationComplete 之后可能会发生注入,但我认为绑定会解决这个问题。

我有一种感觉,模型 - PM - 直到很久以后才为空,并且没有触发函数绑定。

我也尝试使用 FastInject 但无济于事。

这是函数指针和 Flex 绑定的问题吗?

4

1 回答 1

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声明了 Function 变量Bindable,您将看到 3 次“AAA”。如果您删除Bindable元数据,您将看到“A”、“B”、“C”。

很明显,绑定也适用于函数指针(你必须在别处寻找你的空指针)。

于 2012-05-16T09:09:55.660 回答