Is there a way to easily convert cfquery output to DataTable JSON format in coldfusion?

前端 未结 1 417
一生所求
一生所求 2021-01-22 14:39

I am trying to generate a chart using Google Charts API, but I can\'t seem to get the data in the required format.

serializeJSON(data) in coldfusion gives m

相关标签:
1条回答
  • 2021-01-22 15:35

    This is basically what you need. Just plug in your query data.

    <cfset chartsData = structNew()>
    <cfset chartsData["cols"] = arrayNew(1)>
    
    <!--- use a query loop to copy query data to this struct --->
    <cfloop query="UserDetailsResult">
       <cfset chartsRow = structNew()>
       <cfset chartsRow["id"] = ""> 
       <cfset chartsRow["label"] = "SignIn Method">
       <cfset chartsRow["pattern"] = "">
       <cfset chartsRow["type"] = "string">
    
       <cfset arrayAppend(chartsData["cols"], chartsRow)>
    </cfloop>
    
    <cfset chartsDataJSON = serializeJSON(chartsData)>
    
    0 讨论(0)
提交回复
热议问题