在Asp.net MVC 中,使得我們能夠更加自由控制我們所想顯示HTML。通常情況下,都要做一下數據列表。那么我們可以手動去拼一個表格出來,但這樣有時對于復雜的表格說,那就JS代碼比較復雜了。我們可以借助JS下的模板引擎,來實現這一功能。下面要介紹就是JTemplates,它也是基于Jquery的。
}
});
});
function ApplyTemplate(msg) {
$('#Container').setTemplate($("#TemplateResultsTable").html());
$('#Container').processTemplate(msg);
}
</script>
</head>
<body>
<div id="Container"> </div>
<%-- Results Table Template --%>
<script type="text/html" id="TemplateResultsTable">
{#template MAIN}
<table cellpadding="10" cellspacing="0">
<tr>
<th>Username</th>
<th>Password</th>
<th>Url</th>
<th>Email</th>
<th>PassportID</th>
</tr>
{#foreach$Tasuu}
{#includeROWroot=$T.uu}
{#/for}
</table>
{#/templateMAIN}
{#templateROW}
<trclass="{#cyclevalues=['','evenRow']}">
<td>{$T.UserName.bold()}</td>
<td>{$T.Password}</td>
<td>{$T.Url.link($T.Url)}</td>
<td>{$T.Email.link('mailto:'+$T.Email)}</td>
<td>{$T.PassportID}</td>
</tr>
{#/templateROW}
</script>
</body>
</html>
新聞熱點
疑難解答