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

dojo用json实现表格原理
<html>
	<head>
		<title>first Grid</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
		<style type="text/css">
			@import "../dojox/grid/resources/tundraGrid.css";
			@import "../dojo/resources/dojo.css";
		</style>
<script type="text/javascript" src="../dojo/dojo.js" djConfig="parseOnLoad: true"></script>
<script type="text/javascript"> 
	 dojo.require("dojo.data.ItemFileReadStore"); 
	 dojo.require("dojox.grid.DataGrid"); 
	 var sampleData = {identifier: 'pro_no',label: 'pro_no', 
	 items: [ 
	 {pro_no:'2100', pro:'ganliang', min_amount:346, max_amount:931, avg_amount:647}, 
	 {pro_no:'2200', pro:'B Series', min_amount:301, max_amount:894, avg_amount:608}, 
	 {pro_no:'2300', pro:'C Series', min_amount:456, max_amount:791, avg_amount:532}, 
	 {pro_no:'2400', pro:'D Series', min_amount:859, max_amount:2433, avg_amount:1840}, 
	 {pro_no:'2500', pro:'E Series', min_amount:459, max_amount:1433, avg_amount:1040} 
	 ]}; 
	 var jsonStore = new dojo.data.ItemFileReadStore({ data: sampleData }); 
	 var layout = [ 
	 {field: 'pro_no', name: 'Product Number' }, 
	 {field: 'pro', name: 'Product' }, 
	 {field: 'min_amount', name: 'Minimum Amount' }, 
	 {field: 'max_amount', name: 'Maximum Amount' }, 
	 {field: 'avg_amount', name: 'Average Amount' }]; 
 </script>
	</head>
	<body class="tundra">
		<div class="heading">
			First Grid
		</div>
		<div id="grid" dojoType="dojox.grid.DataGrid" store="jsonStore"
			structure="layout" autoWidth="true"></div>
	</body>
</html>
----------------------
({ data: sampleData }); -->({ url: a.jsp}); 却不行
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<%//out.print("[{pro_no:'2100', pro:'ganliang', min_amount:346, max_amount:931, avg_amount:647},{pro_no:'2200', pro:'B Series', min_amount:301, max_amount:894, avg_amount:608},{pro_no:'2300', pro:'C Series', min_amount:456, max_amount:791, avg_amount:532},{pro_no:'2400', pro:'D Series', min_amount:859, max_amount:2433, avg_amount:1840},{pro_no:'2500', pro:'E Series', min_amount:459, max_amount:1433, avg_amount:1040}]") ;
	String ss="{identifier: 'pro_no',label: 'pro_no',";
	 ss = ss+"items: [";  
	 ss = ss+"{pro_no:'2100', pro:'ganliang', min_amount:346, max_amount:931, avg_amount:647},"; 
	 ss = ss+"{pro_no:'2200', pro:'B Series', min_amount:301, max_amount:894, avg_amount:608},"; 
	 ss = ss+"{pro_no:'2300', pro:'C Series', min_amount:456, max_amount:791, avg_amount:532},"; 
	 ss = ss+"{pro_no:'2400', pro:'D Series', min_amount:859, max_amount:2433, avg_amount:1840},"; 
	 ss = ss+"{pro_no:'2500', pro:'E Series', min_amount:459, max_amount:1433, avg_amount:1040}"; 
	 ss = ss+"]}";
	 response.getWriter().write(ss);
	 %>
</body>
</html>