首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何将编辑后的Flex数据网格传递给CFC以插入到数据库中

如何将编辑后的Flex数据网格传递给CFC以插入到数据库中
EN

Stack Overflow用户
提问于 2009-11-04 04:54:20
回答 3查看 1.2K关注 0票数 1

我有一个可编辑的datagrid,我需要将它通过CFC发送回数据库,以便在所有编辑完成后插入到数据库中。将数组集合转储到cfdump会告诉我,我有一个包含项和结构的数组,但我无法理解如何“循环”每个项并插入到DB中。

似乎只有很少的实际有效的代码!我的MXML和CFC如下所示,但给出的错误是“您试图将coldfusion.runtime.Array类类型的标量变量作为带有成员的结构取消引用”。

非常感谢您的帮助-谢谢

代码语言:javascript
复制
[Bindable]
private var getconsent:ArrayCollection = new ArrayCollection([
{LocationName:'Service A', Contact: 'Bob Jones' },  
{LocationName:'Service B', Contact: 'Jane Smith' },
{LocationName:'Service c', Contact: 'Doug Johnson' },   
{LocationName:'Service d', Contact: 'John Jackson'}   
]);  

public function send():void {  
cfdata.sendData(getconsent.source);  
}  

public function send_Result(event:ResultEvent):void {  
Alert.show('ok'); 
}  

public function send_Fault(event:FaultEvent):void {  
Alert.show(event.fault.message);  
} 

]]>  
</mx:Script>  

<mx:RemoteObject 
id="cfdata" 
showBusyCursor="true" 
destination="ColdFusion"  
source="buildtest.test2">  

<mx:method name="sendData" result="send_Result(event)" fault="send_Fault(event)" />  
</mx:RemoteObject>  

<mx:DataGrid id="myGrid" 
dataProvider="{getconsent}" editable="true" > 
<mx:columns>
<mx:DataGridColumn dataField="LocationName" width="150"
editable="false"/>

<mx:DataGridColumn dataField="Contact" width="150" /> 

</mx:columns> 
</mx:DataGrid> 
<mx:Button label="Update DB" click="send()"/>
代码语言:javascript
复制
<cfcomponent displayname="sendData" output="false" >  
    <cffunction name="sendData" access="remote"  output="no" returnType="void"          required="yes" >  

        <cfargument name="getconsent" type="any" required="true">  

        <cfloop from="1" to="#ArrayLen(getconsent.dataprovider)#" index="i">  

            <cfquery name="clientconsent" datasource="gvr">  

                INSERT INTO ClientConsent"
                        (Location)
                VALUES
                ('#getconsent.dataprovider.LocationName[i]#')

            </cfquery>
        </cfloop>
    </cffunction>

</cfcomponent>
代码语言:javascript
复制
 array     1 struct      Contact Bob    Jones
代码语言:javascript
复制
  LocationName   Service A
代码语言:javascript
复制
  mx\_internal\_uid    807D204F-A315-7D78-C745-BAD78087CB28  
代码语言:javascript
复制
 2 struct 
 Contact        Jane Smith  
 LocationName   Service B  
 mx_internal_uid    EAA43EF4-A7EA-82C9-5F3C-BAD780D7FD6F  

 3 struct 
 Contact        Doug Johnson  
 LocationName   Service c  
 mx_internal_uid    9768D6D2-8F97-5F4D-767C-BAD780D7B478 
EN

回答 3

Stack Overflow用户

发布于 2009-11-04 05:29:30

如果您正在使用CF9,请尝试使用Flex4的DCD4:http://ria.dzone.com/articles/flash-remoting-and-coldfusion

如果您在Flex3中使用CF8,请尝试使用LCDS:http://www.adobe.com/devnet/coldfusion/articles/data_app.html

票数 2
EN

Stack Overflow用户

发布于 2009-11-06 00:06:25

使用query对象而不是结构数组会更容易吗?我创建了一个自定义函数,在从您的ArrayCollection应用程序返回后,在CF中将它转换为查询[ArrayCollectionToQuery]。

票数 0
EN

Stack Overflow用户

发布于 2009-11-09 22:40:44

嗨亚当感谢这一点,它看起来非常有用,但我不确定如何使用它来插入数据到我的数据库

代码语言:javascript
复制
<cfquery name="clientconsent" datasource="gvr">
INSERT INTO dbo.ClientConsent
(Location, ClientAppointments, ClientDemographics)
VALUES(
      #qresult#
)
</cfquery>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1670074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档