如何将编辑后的 Flex 数据网格传递到 CFC 以插入到数据库
我有一个可编辑的数据网格,我需要通过 CFC 将其发送回数据库,以便在所有编辑完成后插入数据库。将数组集合转储到 cfdump 告诉我,我有一个包含项目和结构的数组,但我无法理解如何“循环”每个数组并插入到数据库中。
看来真正有用的文章很少!我的 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>
大批 1 结构体 联系鲍勃·琼斯
位置名称服务 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
I have a datagrid which is editable and I need to send that back to the database via a CFC for insertion into the database after all the editing is complete. Dumping the array collection to cfdump tells me that I have an array with items and a structure but i cannot understand how to "loop" through each and insert into the DB.
There seems to be very little written which actually works! My MXML and CFC are below but give me the error of "You have attempted to dereference a scalar variable of type class coldfusion.runtime.Array as a structure with members." -which is nice
all help is much appreciated - thanks
[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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用的是 CF9,请尝试使用 DCD 和 Flex 4:
http://ria.dzone.com/articles/flash-remoting-and- Coldfusion
如果您将 CF8 与 Flex 3 一起使用,请尝试 LCDS:
http://www.adobe.com/devnet/coldfusion/articles/data_app。 html
If you're using CF9, try DCD with Flex 4:
http://ria.dzone.com/articles/flash-remoting-and-coldfusion
If you're using CF8 with Flex 3, try LCDS:
http://www.adobe.com/devnet/coldfusion/articles/data_app.html
使用查询对象而不是结构数组会更容易吗?我创建了一个 UDF,在从 CF 返回后将 ArrayCollection 转换为 CF 中的查询 [ArrayCollectionToQuery]您的 Flex 应用程序。
Would it be easier for you to work with a query object instead of an array of structs? I created a UDF to convert an ArrayCollection to a Query [ArrayCollectionToQuery] in CF after it's returned from your Flex application.
嗨,亚当,谢谢你,它看起来非常有用,但是我不确定如何使用它将数据插入我的数据库
Hi Adam thanks for this it looks very useful, however i am not sure how to use it to insert data into my DB