Flex:通过 CFC 保存可编辑数据网格

发布于 2024-07-14 21:29:05 字数 2000 浏览 4 评论 0原文

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

I have an editable datagrid which I need to be able to save with other form fields via a CFC in ColdFusion.

Basically the aim is that there are a number of locations retrieved via an RO which make up the first column the remaining columns are types of data i.e. demographics, client notes, appointments etc, the idea is that the user tick each of the checkboxes in the grid to indicate that they are happy to share the type of data with those locations. It has to be done this way as the locations may change so there could be two or four or more over time.

The code runs so far runs and looks good but the saving bit is driving me nuts!! Please help.

Thanks in advance
:)
the code (abreviated for reasons of sanity) is below:

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

面犯桃花 2024-07-21 21:29:05

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

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

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

It sounds like what you want to do is return the entire contents of the DataGrid back as a member of the rest of your form data. I'm still learning Flex, but I believe it would automatically be converted from an ArrayCollection to a Query since you're using AMF.

Since you're not using a dataProvider attribute for your DataGrid, I assume you're binding an ArrayCollection object to the DataGrid in the init function you're calling from the creationComplete event. In that case, you'll want to do the opposite before returning the form data to the server: copy the DataGrid values back to a variable you're returning.

Alternatively, you could use a bindable ArrayCollection variable, so that when the DataGrid is updated by the user, the ArrayCollection variable is already updated and you can simply return it back to ColdFusion.

迷爱 2024-07-21 21:29:05

我不知道 CF 中的 Flex,但您是否确定要一次保存所有这些内容还是通过某种“保存”或“提交”操作?

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

否则我只会放一个 监听每个单元格中的onChange事件并实时写入。

I don't know Flex in CF but have you determined if you want to save them all at once or on some sort of "Save" or "Submit" action?

If you are going to save them all at once then this post on Iterating over a ColdFusion Query in Flex may be helpful.

Otherwise I would just put a Listener on the onChange event in each cell and write it in real time.

Oo萌小芽oO 2024-07-21 21:29:05

我需要做类似的事情,我发现在 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就是这样的。 确保将别名属性设置为与 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: //mxbase.blogspot.com/2008/07/passing-custom-objects- Between-flex-and.html

I needed to do something similar and I found it worked nicely to create a "data set" object in actionscript and an analogous CFC that would map to each other. From flex, call the remote method passing the actionscript object, then on the CF side it will be translated as to the cfc.

[RemoteClass(alias = "model.DataSet")] **//maps to the CFC**    
[Bindable]
public class DataSetVO
{       

    public var rows:Array;

    public function DataSetVO() 
    {

    }

}

The CFC is like this. Make sure to set the alias attribute to match the alias set in the RemoteClass of the actionscript object:

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

The CFC method to save the data can be like

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

The call from flex is like:

 //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);  

Mapping complex objects from Flex to CF can be a little tricky but once it's set up it very nice.

These articles may be helpful

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文