1

我有一个可编辑的数据网格,我需要能够通过 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>
4

3 回答 3

1

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

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

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

于 2009-03-13T15:45:19.147 回答
0

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

如果您打算一次保存它们,那么这篇关于在 Flex 中迭代 ColdFusion 查询的帖子可能会有所帮助。

否则我只会在每个单元格中的 onChange 事件上放置一个监听器并实时编写它。

于 2009-03-13T00:43:03.353 回答
0

我需要做一些类似的事情,我发现它可以很好地在 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

于 2009-09-30T18:17:04.950 回答