【问题标题】:Function binding not set after model is injected模型注入后未设置函数绑定
【发布时间】:2012-05-23 10:56:44
【问题描述】:

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

CustomDataGridColumn 具有 Function 类型的成员变量。

在我的视图中,我使用 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 绑定的问题吗?

【问题讨论】:

  • 不是对您问题的回答,而是一个观察:除非您想更改或添加其功能,否则不应扩展 GridColumn。几乎没有任何需要。我最近有一个similar discussion。

标签: apache-flex datagrid parsley datagridcolumn


【解决方案1】:

不,不是。如果您有这些疑问,最好快速设置一个简单的隔离测试情况来验证您的假设。我创建了以下内容来测试您的:

<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”。

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

【讨论】:

    猜你喜欢
    • 2020-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多