ColdBox JSON and jQuery template plugin

I'm just trying out ColdBox with jQuery/Microft template plugin. I'm
using ColdBox's renderData method to return a JSON representation of a
query, and the result looks something like this:
   {"recordcount":3,"columnlist":"messageid,messagetext,dateposted,firstname,lastname","data":{"messageid":[3,2,1],"messagetext":["hello?
is this thing on???","what? why?","Hello, and
welcome!"],"dateposted":["{ts '2010-12-05 11:32:51'}","{ts '2010-12-05
11:32:17'}","{ts '2010-12-05
09:44:30'}"],"firstname":["Mortimer","Tom","Waldo"],"lastname":["Who","Dickenharry","Emerson"]}}

that makes sense but, I'm having trouble on the client side using that
with the template plugin. It expects an array of individual objects,
each with a field for each query column. The ColdBox JSON response is
an object containing recordcount, columnlist, and data members, where
the data piece is an object keyed by column name, whose values are
arrays with the data for each record. It's equivalent, and more
concise, but not the same.

So:

- Is there a way to tell ColdBox to serialize this as an array of
objects, rather than this format? Yes I know I could write it myself,
just wondering if I'm missing something obvious that's already done.

- Better yet, is there a way for jQuery to convert this json format to
the array of objects the template plugin is looking for, or make use
of it in its current format?

Thanks,
Dave

Try passing jsonAsText=true as an argument in renderData()

N

Nolan Dubeau

Load *.*,8,1

I just did something like this for extJS, with some custom tags that I am
writing. The problem is that with ExtJS I had to intercept the return data,
after being read but before sticking the data into the store. I am not sure
how jQuery does this but if you want to use the ColdFusion tags you will
need to do the same thing and intercept the data after being read from the
server, but before the data is used.

Regards,
Andrew Scott
http://www.andyscott.id.au/

From: coldbox@googlegroups.com [mailto:coldbox@googlegroups.com] On
Behalf Of Dave Merrill
Sent: Monday, 6 December 2010 5:03 AM
To: coldbox@googlegroups.com
Subject: [coldbox:7093] ColdBox JSON and jQuery template plugin

I'm just trying out ColdBox with jQuery/Microft template plugin. I'm using
ColdBox's renderData method to return a JSON representation of a query,
and the result looks something like this:

{"recordcount":3,"columnlist":"messageid,messagetext,dateposted,firstnam
e,lastname","data":{"messageid":[3,2,1],"messagetext":["hello?
is this thing on???","what? why?","Hello, and

welcome!"],"dateposted":["{ts

'2010-12-05 11:32:51'}","{ts '2010-12-05 11:32:17'}","{ts '2010-12-05
09:44:30'}"],"firstname":["Mortimer","Tom","Waldo"],"lastname":["Who","D
ickenharry","Emerson"]}}

that makes sense but, I'm having trouble on the client side using that

with

the template plugin. It expects an array of individual objects, each with

a field

for each query column. The ColdBox JSON response is an object containing
recordcount, columnlist, and data members, where the data piece is an
object keyed by column name, whose values are arrays with the data for
each record. It's equivalent, and more concise, but not the same.

So:

- Is there a way to tell ColdBox to serialize this as an array of objects,

rather

than this format? Yes I know I could write it myself, just wondering if

I'm

missing something obvious that's already done.

- Better yet, is there a way for jQuery to convert this json format to the

array

of objects the template plugin is looking for, or make use of it in its

current

http://www.coldbox.org/documents/api/ColdBoxDocs-3.0.0.RC1/coldbox/system/web/context/RequestContext.html#renderData()

If you read the API docs you will see: jsonQueryFormat - JSON Only: query or array

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

But what if you are using ColdFusion code to return the information like what is needed for the Grid?

Regards,

Andrew Scott

http://www.andyscott.id.au/

Thanks guys.

@Nolan, that changes how the return structure is encoded, but it's
still in the same overall format. It's actually far more efficient
than an array of objects with redundant key names.

@Andrew and anyone else, I wrote a js function to "flatten" the JSON
data into an array of objects that the jQuery plugin can deal with.
It's simple and tiny and works fine. I was more wondering if there was
some built-in strategy, either on the ColdBox side, or ideally, on the
client, since that transmits the data in the less verbose form.

@Luis, thanks, I missed that, looks like exactly what I needed if I
wanted to change the return data format, I'll check it out. I'll
probably stick with the query format since it's so much more concise,
and deal with it on the client, but it's good to know. Still waiting
to hear from folks on the jQuery side if they have a way to deal with
this. It's a common format, so maybe so.

Dave