Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--- Create the query --->
- <cfscript>
- myQuery=queryNew("fruit,color","Integer,Varchar",[ ["apples","green"], ["banannas","yellow"], ["grapes","purple"] ]);
- function QueryToArrayOfStructures(theQuery){
- var theArray = arraynew(1);
- var cols = ListtoArray(theQuery.columnlist);
- var row = 1;
- var thisRow = "";
- var col = 1;
- for(row = 1; row LTE theQuery.recordcount; row = row + 1){
- thisRow = structnew();
- for(col = 1; col LTE arraylen(cols); col = col + 1){
- thisRow[cols[col]] = theQuery[cols[col]][row];
- }
- arrayAppend(theArray,duplicate(thisRow));
- }
- return(theArray);
- }
- result = queryToArrayOfStructures( myQuery );
- writedump( result );
- writedump( serializeJSON( result ) );
- </cfscript>
- <cfoutput>
- <script>
- var deets = JSON.parse( '#serializeJSON( result )#' );
- for( var i=0; i<deets.length; i++ ) {
- alert( deets[ i ].COLOR );
- }
- </script>
- </cfoutput>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement