【问题标题】:Flex: Save an editable datagrid via a CFCFlex:通过 CFC 保存可编辑的数据网格
【发布时间】:2009-03-12 19:13:42
【问题描述】:

我有一个可编辑的数据网格,我需要能够通过 ColdFusion 中的 CFC 将其与其他表单字段一起保存。

基本上,目标是通过 RO 检索到多个位置,这些位置构成第一列,其余列是数据类型,即人口统计、客户备注、约会等,其想法是用户勾选每个网格中的复选框表示他们很乐意与这些位置共享数据类型。必须以这种方式完成,因为位置可能会发生变化,因此随着时间的推移可能会有两个或四个或更多。

到目前为止运行的代码运行起来看起来不错,但是节省的代码让我发疯了!!请帮忙。

提前致谢 :) 代码(出于理智的原因而缩写)如下:

public function handleconsentResult(event:ResultEvent):void {
            consentDatagrid.dataProvider = event.result;
            }
<mx:RemoteObject id="consentQuery"
    destination="ColdFusion"
    source="Build3.consent"
    showBusyCursor="true">
    <mx:method name="getconsent" result="handleconsentResult(event)" fault="fault(event)" />

<mx:DataGrid id="consentDatagrid" creationComplete="init()" width="98%" wordWrap="true" textAlign="center">
                        <mx:columns>
                            <mx:DataGridColumn headerText="Organisation" width="100" textAlign="left" id="Location" dataField="LocationName" wordWrap="true"/>
                            <mx:DataGridColumn headerText="Demographics"  width="100" wordWrap="true" textAlign="center" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true" editorDataField="ClientDemographics" />
                            <mx:DataGridColumn headerText="Appointments"  width="100" wordWrap="true" textAlign="center" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true" editorDataField="ClientAppointments"/>
                            <mx:DataGridColumn headerText="Activity"  width="70" wordWrap="true" textAlign="center" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true" editorDataField="ClientActivity"/>
                            <mx:DataGridColumn headerText="Notes" width="50" wordWrap="true" textAlign="center" itemRenderer="mx.controls.CheckBox" rendererIsEditor="true" editorDataField="ClientNotes"/>
                        </mx:columns>
                    </mx:DataGrid>

【问题讨论】:

    标签: apache-flex datagrid coldfusion cfc


    【解决方案1】:

    听起来您想要做的是将 DataGrid 的全部内容作为其余表单数据的成员返回。我还在学习 Flex,但我相信它会自动从 ArrayCollection 转换为 Query,因为您使用的是 AMF。

    由于您没有为 DataGrid 使用 dataProvider 属性,我假设您在从 creationComplete 事件调用的 init 函数中将 ArrayCollection 对象绑定到 DataGrid。在这种情况下,您需要在将表单数据返回到服务器之前执行相反的操作:将 DataGrid 值复制回您要返回的变量。

    或者,您可以使用可绑定的 ArrayCollection 变量,这样当用户更新 DataGrid 时,ArrayCollection 变量已经更新,您可以简单地将其返回给 ColdFusion。

    【讨论】:

      【解决方案2】:

      我不知道 CF 中的 Flex,但您确定是要一次性保存它们还是通过某种“保存”或“提交”操作?

      如果您打算一次保存所有这些,那么Iterating over a ColdFusion Query in Flex 上的这篇帖子可能会有所帮助。

      否则我只会在每个单元格的 onChange 事件上添加一个Listener 并实时写入。

      【讨论】:

        【解决方案3】:

        我需要做一些类似的事情,我发现它可以很好地在 actionscript 中创建一个“数据集”对象和一个可以相互映射的类似 CFC。从 flex 调用传递 actionscript 对象的远程方法,然后在 CF 端它将被转换为 cfc。

        [RemoteClass(alias = "model.DataSet")] **//maps to the CFC**    
        [Bindable]
        public class DataSetVO
        {       
        
            public var rows:Array;
        
            public function DataSetVO() 
            {
        
            }
        
        }
        

        CFC 就是这样。确保将 alias 属性设置为与 actionscript 对象的 RemoteClass 中设置的别名匹配:

        <cfcomponent name="DataSet"  alias="model.DataSet"> 
        <cfproperty name="rows" type="array" />
        </cfcomponent>
        

        保存数据的CFC方法可以是这样的

            <cffunction name="saveToFile" access="remote" returntype="numeric" hint="">
            <cfargument name="dataSet" type="model.GPDataSet" required="true" />
            <!--- do what you need to do to with arguments.dataSet to 
                          save to a file, database, whatever --->
            <cfreturn 0 />
        </cffunction>
        

        来自 flex 的调用是这样的:

         //make a remote call to save the grid 
         //populate your VO with the contents of the grid, in this case I have an object
         //that gives me one, basically iterate over the dataprovider of the grid
        var myVO:DataSetVO = myDataSet.getAsVO();
        //calling the remote CFC passing the VO that will be mapped to a CFC on the server
        cfsvc.saveToFile(myVO);  
        

        将复杂对象从 Flex 映射到 CF 可能有点棘手,但一旦设置好就非常好。

        这些文章可能会有所帮助

        http://www.jeffryhouser.com/index.cfm/2007/10/9/Why-does-ColdFusion-return-a-CFC-to-Flex-as-a-generic-object

        http://mxbase.blogspot.com/2008/07/passing-custom-objects-between-flex-and.html

        【讨论】:

          猜你喜欢
          • 2011-03-04
          • 1970-01-01
          • 2011-01-11
          • 2012-02-10
          • 2011-01-29
          • 1970-01-01
          • 2013-03-08
          • 2011-04-24
          • 2020-09-05
          相关资源
          最近更新 更多