我有一个可编辑的datagrid,我需要将它通过CFC发送回数据库,以便在所有编辑完成后插入到数据库中。将数组集合转储到cfdump会告诉我,我有一个包含项和结构的数组,但我无法理解如何“循环”每个项并插入到DB中。
似乎只有很少的实际有效的代码!我的MXML和CFC如下所示,但给出的错误是“您试图将coldfusion.runtime.Array类类型的标量变量作为带有成员的结构取消引用”。
非常感谢您的帮助-谢谢
[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()"/><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> array 1 struct Contact Bob Jones LocationName Service A mx\_internal\_uid 807D204F-A315-7D78-C745-BAD78087CB28 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 发布于 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
发布于 2009-11-06 00:06:25
使用query对象而不是结构数组会更容易吗?我创建了一个自定义函数,在从您的ArrayCollection应用程序返回后,在CF中将它转换为查询[ArrayCollectionToQuery]。
发布于 2009-11-09 22:40:44
嗨亚当感谢这一点,它看起来非常有用,但我不确定如何使用它来插入数据到我的数据库
<cfquery name="clientconsent" datasource="gvr">
INSERT INTO dbo.ClientConsent
(Location, ClientAppointments, ClientDemographics)
VALUES(
#qresult#
)
</cfquery>https://stackoverflow.com/questions/1670074
复制相似问题