我需要使用 JSON 格式的数据生成报告。这是接收参数并显示带有数据的 html 表或 excel 的操作文件。我在解析 JSON 数据时需要帮助,我正在进入所需的格式(html 或 excel)。我知道如何使用 excel 格式,我只需要解析 JSON 数据并输出它的帮助。
<cfajaxproxy cfc="components.acct.accttrx">
<script src="../jQuery/js/jquery-1.7.2.min.js"></script>
<cfparam name="prD" default="0_0">
<cfparam name="sM" default="1">
<cfparam name="sY" default="2013">
<cfparam name="status" default="0">
<cfparam name="FORM.fileformat" default="html">
<script type="text/javascript">
jQuery(document).ready(function(){
var myURL = '../components/acct/accttrx.cfc';
function populateReport(){
$.ajax({
url: myURL + "?method=GetTranactions",
type: 'POST',
data: {
prID: '<cfoutput>#prD#</cfoutput>',
mn: '<cfoutput>#sM#</cfoutput>',
yr: '<cfoutput>#sY#</cfoutput>',
st: '<cfoutput>#status#</cfoutput>',
ea_adm:'1',
slist:'',
lang: '1'
},
dataType: "json",
success:
function(data){
$.each(data, function(index, item) {
//(item.description,item.balance,item.accttrx_status);
// I need help from this point to pass
// data to cfml part of my code
});
},
error:
function(){
alert("An error has occurred while fetching records");
}
});
populateReport();
});
</script>
</HEAD>
<body>
<cfif FORM.fileformat Eq 'excel'>
<cfset VARIABLES.vcFilename = "thisreport_" & DateFormat(Now(), "yyyymmdd") & "-" & TimeFormat(Now(), "HHmmss") & ".xls">
<cfsetting enablecfoutputonly="Yes">
<cfcontent type="application/vnd.ms-excel">
<cfheader name="Content-Disposition" value="inline;filename=""#VARIABLES.vcFilename#""">
<cfoutput>
<!--- here display data from JSON object --->
</cfoutput>
<cfsetting enablecfoutputonly="No">
<cfelse>
<div id="reportcontents" /> <!--- display row html --->
</cfif>
这是来自响应的数据:
{"ROWS":[ { "balance":-642.04000, "description":"ABC Company", "ee_name":"Jon, Doe", "plan_id":0, "debit":25000.22000, "accttrx_year":2013 ,“sponsor_id”:5,“division_id”:0,“accttrx_month”:1,“credit”:26591.25000,“trx_employee_id”:1,“cheque_amt”:25000.00000,“cheque_no”:“”,“accttrx_status”:“B ", "accttrx_id":15 }, { "balance":-642.04000, "description":"ABC 公司", "ee_name":"James, Done", "plan_id":0, "debit":32233.07000, "accttrx_year “:2013,”赞助商id”:5,“部门id”:0,“accttrx_month”:1,“信用”:30000.00000,“trx_employee_id”:1,“cheque_amt”:32233.07000,“cheque_no”:“”,“accttrx_status”:“P”, “accttrx_id”:14 } ],“PAGE”:1,“记录”:2,“TOTAL”:1.0 }