<script src="~/Js/jquery-2.1.0.js"></script>
<script src="~/Js/jquery-jtemplates.js"></script>
<script type="text/javascript">
$(function ($) {
var data= {
"AgentList": [ {
"nAgentID": "2317",
"sAgentCode": "JLS",
"sAgentName": "九岭山"
} ],
"DepartmentList": [ {
"nDepartmentID": "2",
"sDepartmentCode": "WW",
"sDepartmentName": "王五",
"nAgentid": "2315"
}, {
"nDepartmentID": "3",
"sDepartmentCode": "ZS",
"sDepartmentName": "张三",
"nAgentid": "2315"
} ]
}
$(‘#foreachResult‘).setTemplate($(‘#foreach‘).html()).processTemplate(data);
});
</script>
<script type="text/template" id="foreach">
<table>
<thead>
<tr>
<td>hehehe</td>
<td>gagaga</td>
<td>hahaha</td>
</tr>
</thread>
<tbody>
{#foreach $T.AgentList as record begin=0}
<tr>
<td>{$T.record.nAgentID}</td>
<td>{$T.record.sAgentCode}</td>
<td>{$T.record.sCommission}</td>
</tr>
{#/for}
<p><br><br>
{#foreach $T.DepartmentList as record begin=0} 这个begin 就是在那条记录开始,在1开始第0条省略。类推
<tr>
<td>{$T.record.nDepartmentID}</td>
<td>{$T.record.sDepartmentCode}</td>
<td>{$T.record.sDepartmentName}</td>
</tr>
{#/for}
</tbody>
</table>
</script>
<body>
<div id="foreachResult"></div>
</body>