2012-05-15 26 views
0

我有一个从DataGrid和从DataGridColumn扩展的CustomDataGridColumn扩展的CustomDataGrid。注入模型后没有设置函数绑定

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

欧芹语境文件在上述文件的父,并声明PM如下:

AssocDocPMFactory是装饰有[出厂]鞋底函数的类。

所以问题是:

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

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

我明白注入可能会在creationComplete被调用后发生,但我认为绑定会照顾到这一点。

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

我试图使用FastInject,但无济于事。

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

+0

不是你的问题的答案,而是一个观察:你不应该扩展GridColumn,除非你想改变或添加到它的功能。几乎没有任何需要。我最近有一个[类似的讨论](http://stackoverflow.com/questions/10520158/flex-application-is-confused-when-passing-variables-to-custom-component)。 – RIAstar

回答

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

如此明确的绑定工作与函数指针也(你必须寻找其他地方找到你的空指针)。