如何格式化从coldfusion到jquery fullcalendar的json feed?

wbl*_*enc 2 coldfusion json fullcalendar

我正在尝试为jquery Full Calendar插件提供json feed,但我没有太多运气.我从coldfusion回来的数据格式不正确(至少这是我的猜测).这是我要回来的:

{"COLUMNS":["TITLE","START","END","REQUEST_TYPE_ID"],"DATA":[["duration of a VTC ","2012-03-15T12:00:00Z","2012-03-15T15:00:00Z",1],["a new vtc overlap","2012-03-15T11:45:00Z","2012-03-15T14:15:00Z",1]]} 
Run Code Online (Sandbox Code Playgroud)

我很确定完整日历不知道如何读取此数据类型.所以问题是,我可以让CF以完整日历接受的格式传回数据吗?这里还有别的东西吗?

这是我的组件:

<cfquery datasource="#arguments.dsn#" name="eventlist">
select title, to_char(start_time,'YYYY-MM-DD')||'T'||to_char(start_time,'HH24:MI:SS')||'Z' as "start", 
to_char(start_time,'YYYY-MM-DD')||'T'||to_char(start_time + (duration/1440),'HH24:MI:SS')||'Z' as "end", request_type_id
from ((request r join event_schedule es on es.request_id = r.id)left join location_ref loc on loc.location_id = r.location_id) 
where site_id = <cfqueryparam value="#arguments.site_id#" cfsqltype="cf_sql_varchar" />
and request_type_id = <cfqueryparam value="#arguments.evnttype#" cfsqltype="cf_sql_varchar" />
and start_time between to_date('#sdate#', 'mon dd yyyy') and to_date('#edate#', 'mon dd yyyy')
</cfquery>
Run Code Online (Sandbox Code Playgroud)

并且返回格式是json.

returnformat="json"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

谢谢!

bay*_*ezy 7

您需要格式化数据才能使插件正常工作.它必须是一个事件对象数组http://arshaw.com/fullcalendar/docs/event_data/Event_Object/

因此,您需要循环查询并使用上述链接中的文档中指定的键创建一个结构数组.

您将需要使用数组表示法,因为JavaScript对变量名称区分大小写,CF喜欢在默认情况下将结构中的键设置为大写.

这样做: -

<cfset myStruct["id"] = 1>
Run Code Online (Sandbox Code Playgroud)

代替:-

<cfset myStruct.id = 1>
Run Code Online (Sandbox Code Playgroud)

我希望有所帮助.

  • 您可以使用SerializeJSON()或使用`returnformat ='json'从cffunction返回数据 (3认同)