July 25, 2008
For ColdFusion hosting try HostMySite.com. |
Home /
Groups /
Adobe Flex 2
How do you handle an arraycollection in ColdFusion ?
Hi there,jason robinson 05/14/08 05:51 P You're going to hit yourself in the head when I say this, but have you triedJennifer Larkin 05/14/08 06:00 P Oh nevermind, you said you did that. You could just leave the type off andJennifer Larkin 05/14/08 06:00 P If you're not a praying man, don't send the ArrayCollection.Charlie Griefer 05/14/08 06:15 P >If you're not a praying man, don't send the ArrayCollection.jason robinson 05/14/08 06:34 P jasPaul Hastings 05/14/08 07:00 P > I have a Flex app where I pass an arraycollection to my cfc.Dave Watts 05/14/08 06:37 P Hi there, I have a Flex app where I pass an arraycollection to my cfc. I've been trying to set the argument type as a 'struct' but I get an error stating that my arraycollection is not of type struct. I've also tries setting it as an array. No luck. Any thoughts? Thanks. Novian Code: <cffunction name="saveQuiz" access="remote" returntype="boolean" hint="Saves new quiz to quiz_questions."> <cfargument name="quizQuestion" type="string" required="yes"> <cfargument name="quizAnswer" type="string" required="yes"> <cfargument name="optionsAC" type="struct" required="yes"> <cfset var qRead=""> <cfquery name="savedQuizQuestion" datasource="my_db" result="savedQuizID"> INSERT into quiz_questions (quizQuestion, quizAnswer) VALUES ('#ARGUMENTS.quizQuestion#', '#ARGUMENTS.quizAnswer#') </cfquery> <cfloop from="1" to="#ArrayLen(optionsAC.optionsArray)#" index="i"> <cfquery name="savedQuizOptions" datasource="my_db"> INSERT into quiz_options (quizID, optionName, correct) VALUES ('#savedQuizID.GENERATED_KEY#', '#optionsAC.optionsArray[i].label#', '#optionsAC.optionsArray[i].data#') </cfquery> </cfloop> <cfreturn true> </cffunction> You're going to hit yourself in the head when I say this, but have you tried type="array"? On Wed, May 14, 2008 at 2:50 PM, jas ----- Excess quoted text cut - see Original Post for more ----- Oh nevermind, you said you did that. You could just leave the type off and pray. On Wed, May 14, 2008 at 2:59 PM, Jennifer Larkin <jlarkin@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- If you're not a praying man, don't send the ArrayCollection. ArrayCollection is really just a wrapper for an array that adds some extra functionality like getItemAt(). Pass in the underlying array, which would be optionsAC.source. then you'll be able to type your cfargument to an array. On Wed, May 14, 2008 at 2:59 PM, Jennifer Larkin <jlarkin@gmail.com> wrote: ----- Excess quoted text cut - see Original Post for more ----- ----- Excess quoted text cut - see Original Post for more ----- Thanks for the quick reply, guys. Charlie: You're right, I'm not a praying man AND your advice worked! :) Thanks so much. I've included the amended code in case anyone is interested. Code: <cffunction name="saveQuiz" access="remote" returntype="boolean" hint="Saves new quiz to quiz_questions."> <cfargument name="quizQuestion" type="string" required="yes"> <cfargument name="quizAnswer" type="string" required="yes"> <cfargument name="optionsAC" type="array" required="yes"> <cfset var qRead=""> <cfquery name="savedQuizQuestion" datasource="my_db" result="savedQuizID"> INSERT into quiz_questions (quizQuestion, quizAnswer) VALUES ('#ARGUMENTS.quizQuestion#', '#ARGUMENTS.quizAnswer#') </cfquery> <cfloop from="1" to="#ArrayLen(optionsAC)#" index="i"> <cfquery name="savedQuizOptions" datasource="my_db"> INSERT into quiz_options (quizID, optionName, correct) VALUES ('#savedQuizID.GENERATED_KEY#', '#optionsAC[i].label#', '#optionsAC[i].data#') </cfquery> </cfloop> <cfreturn true> </cffunction> jas ----- Excess quoted text cut - see Original Post for more ----- just to nit pick, your forgot to var scope your cfloop index "i" & the names of your queries (savedQuizQuestion & savedQuizOptions). and what you do var scope (qRead) doesn't seem to get used. > I have a Flex app where I pass an arraycollection to my cfc. > I've been trying to set the argument type as a 'struct' but I > get an error stating that my arraycollection is not of type > struct. I've also tries setting it as an array. No luck. > Any thoughts? I don't think ArrayCollection is supported by Flash Remoting. The specific datatypes supported are listed here: http://livedocs.adobe.com/coldfusion/8/htmldocs/usingSalsaN_4.html Dave Watts, CTO, Fig Leaf Software http://www.figleaf.com/ Fig Leaf Training: Adobe/Google/Paperthin Certified Partners http://training.figleaf.com/ WebManiacs 2008: the ultimate conference for CF/Flex/AIR developers! http://www.webmaniacsconference.com/
|
Mailing Lists
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||