query to json oblect - that can be referenced by a unique id


/ Published in: JavaScript
Save to your folder(s)

in javascript use, for example: myJsonObject["js007"].firstname + ' ' + myJsonObject["js007"].lastnamename
to return James Bond


Copy this code and paste it in your HTML
  1. <cfscript>
  2. function nowhitespace(queryname,uniqueIdColumnName,columnlist,recordcount) {
  3. var p="";
  4. var currentrow = 1;
  5. p = p & '"RECORDCOUNT":' & recordcount & ',' & '"UNIQUEIDS":[';
  6. for (ids = 1; ids lte recordcount; ids = ids+1){
  7. p = p & '"js' & evaluate("queryname." & uniqueIdColumnName & '[' & ids & ']') & '"';
  8. if (ids lt recordcount) {p = p & ',';}
  9. else {p = p & '],';}
  10. }
  11. p = p & '"COLUMNNAMES":[' & listQualify(columnlist,'"') & '],';
  12. for (idx = 1; idx lte recordcount; idx = idx+1)
  13. {
  14. p = p & '"js' & evaluate("queryname." & uniqueIdColumnName & '[' & idx & ']') & '"' & ':{';
  15. p = p & '"CURRENTROW":' & currentrow & ',';
  16. for (idx1 = 1; idx1 lte listlen(columnlist); idx1 = idx1+1){
  17. clmnname = listgetat(columnlist,idx1);
  18. p = p & '"' & clmnname & '":';
  19. evalp = evaluate("queryname." & clmnname & '[' & idx & ']');
  20. if (NOT isNumeric(evalp)) {evalp = '"' & JSStringFormat(evalp) & '"';}
  21. if (idx1 IS listlen(columnlist)){p = p & evalp;}
  22. else {p = p & evalp & ',';}
  23. }
  24. if (idx NEQ recordcount) {
  25. p = p & '},';
  26. currentrow = currentrow + 1;
  27. }
  28. } idx1 = 1;
  29. p = p & '}';
  30. return '{' & p & '}';
  31. }
  32. </cfscript>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.