在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>
上一篇:使用linq读取分隔符文本文件
下一篇:datatable行转列示例分享