日期:2014-05-16  浏览次数:20363 次

ajax返回json
	function getAccountCheckDifference(recordId,balance,acountBalance){
		var ajaxObj1=new nstc.AjaxObject();
		ajaxObj1.initRequest(queryCallBack,'text');
		ajaxObj1.doGet("wcl_ra_35_02_02.do?recordId=" + recordId);
	}

	function queryCallBack(jsonObj,balance,acountBalance) {
		if(jsonObj != null){
			var jsonArry = jsonObj.parseJSON();
			if (jsonArry != ""&&jsonArry !='null') {
				 var frt = 0;
			     var fpt = 0;
			     var mrt = 0;
			     var mpt = 0;
			     var actDate,vchNo,f1,f2,m1,m2,row,cell;
			     var sugest;
			     
			     for (var i=mainTable2.rows.length-7;i>1;i--){
			     	row = mainTable2.rows[i];
		     		mainTable2.firstChild.removeChild(row);
			     }
			     
				 for(var i = 0 ; i < jsonArry.length; i++) {
				 	 if (i==jsonArry.length-1){
				 	 	balance = jsonArry[i].Balance;
				 	 	sugest = jsonArry[i].Suggestion;
				 	 	continue;
				 	 }
				     
				     actDate = jsonArry[i].ActDate;
				     vchNo = jsonArry[i].VchNo;
				     f1 = jsonArry[i].Frec?parseFloat(jsonArry[i].Frec):0;
				     f2 = jsonArry[i].Fpay?parseFloat(jsonArry[i].Fpay):0;
				     m1 = jsonArry[i].Mrec?parseFloat(jsonArry[i].Mrec):0;
				     m2 = jsonArry[i].Mpay?parseFloat(jsonArry[i].Mpay):0;
				 	 
					 frt += f1;
				     fpt += f2;
				     mrt += m1;
				     mpt += m2;
					
				     document.getElementById("frt").innerHTML = "&nbsp;"+frt.toFixed(2);	
				     document.getElementById("fpt").innerHTML = "&nbsp;"+fpt.toFixed(2);
				     document.getElementById("mrt").innerHTML = "&nbsp;"+mrt.toFixed(2);
				     document.getElementById("mpt").innerHTML = "&nbsp;"+mpt.toFixed(2);
				     
				     row = mainTable2.insertRow(i+2);
				     cell = row.insertCell(0);
				     cell.style.textAlign = "center";
				     cell.innerText = actDate;
				     cell = row.insertCell(1);
				     cell.style.textAlign = "left";
				     cell.innerText = vchNo;
				     cell = row.insertCell(2);
				     cell.style.textAlign = "right";
				     cell.innerText = f1;
				     cell = row.insertCell(3);
				     cell.style.textAlign = "right";
				     cell.innerText = f2;
				     cell = row.insertCell(4);
				     cell.style.textAlign = "right";
				     cell.innerText = m1;
				     cell = row.insertCell(5);
				     cell.style.textAlign = "right";
				     cell.innerText = m2;
				     cell = row.insertCell(6);
				     cell.style.textAlign = "right";
				     cell.innerText = " ";
				     
			     }
			     
			     frt = FormatMoney(frt,2,"");
			     fpt = FormatMoney(fpt,2,"");
			     mrt = FormatMoney(mrt,2,"");
			     mpt = FormatMoney(mpt,2,"");
			     
			     var mbalanceVal=FormatMoney(balance,2,"");
			     document.getElementById("mbalance").innerHTML = "&nbsp;"+mbalanceVal;	
			     if (sugest && sugest!=null && sugest!='')
			     	document.getElementById("suggestion").value = sugest;
			     
			     var adjfinance=0;
			     var adjMember=0;
			     calcuFinance(frt,fpt,mrt,mpt,balance);
			     calcuMember(frt,fpt,mrt,mpt,balance);
			     amtDiff(adjfinance,adjMember);
			}else{
				document.getElementById("frt").innerHTML = "&nbsp;";
				document.getElementById("fpt").innerHTML = "&nbsp;";
			    document.getElementById("mrt").innerHTML = "&nbsp;";
			    document.getElementById("mpt").innerHTML = "&nbsp;";
			    document.getElementById("mbalance").innerHTML = "&nbsp;";
			    $("adjustFval").innerHTML="&nbsp;";	
			    $("adjustMval").innerHTML="&nbsp;"
			    $("amountdif").innerHTML="&nbsp;"
			}
		}
	}

?后台java处理返回json

?

	private JSONArray getJson(AccountCheckDifference[] diffArry) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		JSONArray json = new JSONArray();
		for (int i = 0; i < diffArry.length; i ++) {
			JSONObject t = new JSONObject();
			try {
				t.put("Id", CastUtil.trimNull(diffArry[i].getId