我正在尝试使用cfc中的JSON字符串来提供FullCalendar的事件部分。 cfc返回数据,但我无法以此插件所需的格式返回数据。日历未响应事件。 在设置cfc以返回正确的格式时,我需要做什么。 我得到的JSON看起来像这样。
[["id: 237","title: Robert Byrd - First Appt.","start: 2011-05-24 11:00:00.0","allDay: false"],["id: 238","title: Margie Hambro - First Appt.","start: 2011-05-14 08:00:00.0","allDay: false"],["id: 302","title: Judy Nichols - First Appt.","start: 2011-05-17 15:50:00.0","allDay: false"],["id: 303","title: Ben Parker - First Appt.","start: 2011-05-23 10:15:00.0","allDay: false"],["id: 304","title: Robert Lentz - First Appt.","start: 2011-05-24 11:25:00.0","allDay: false"]]
<cffunction name="getLeadAppointments" access="remote" returnformat="json" returntype="any">
<cfargument name="start" type="any" required="true" default="">
<cfargument name="end" type="any" required="true" default="">
<!--- Get data --->
<cfquery name="data" datasource="#VARIABLES.dsn#">
SELECT LS.LeadSched_ID AS id,
LTRIM(COALESCE (CM.Contact_FName, '') + ' ' + COALESCE (CM.Contact_LName, '') + ' - ' + LD.DevType_Desc) AS event,
LS.LeadSched_TargetDate AS Start,
LS.LeadSched_ActualDate
FROM ...
Where convert(varchar(25), LS.LeadSched_TargetDate) BETWEEN #dateAdd("s", ARGUMENTS.start, "01/01/1970")# AND #dateAdd("s", ARGUMENTS.end, "01/01/1970")#
</cfquery>
<cfsilent>
<cfset calEvents = ArrayNew(2)>
<cfoutput query="data">
<cfset calEvents[#currentRow#][1] = 'id: #data.id#'>
<cfset calEvents[#currentRow#][2] = 'title: #data.event#'>
<cfset calEvents[#currentRow#][3] = 'start: #data.start#'>
<cfset calEvents[#currentRow#][4] = 'allDay: false'>
</cfoutput>
<cfset calData = SerializeJSON(data)>
</cfsilent>
<cfreturn calEvents>
</cffunction>
答案 0 :(得分:1)
这是猜测,但我强烈怀疑您的客户端代码需要看起来更像这样的内容:
[{"id": "237","title": "Robert Byrd - First Appt.","start": "2011-05-24 11:00:00.0","allDay": false}, ...]
请注意,外部数组中的条目在此处从字符串数组(如您所示)更改为对象,并且您的原始字符串已被拆分为两个(除了最后的布尔属性,“allDay”,其中给出了JSON本机布尔值false
)。
答案 1 :(得分:0)
您是否已将JSON指定为cffunction中的returnformat?
<cffunction name="myCoolFunction" returnformat="JSON" ... >
如果您可以发布cffunction本身,而不仅仅是结果,那将有助于进一步调试。