網(wǎng)(LieHuo.Net)教程 工作中需要在前端將json數(shù)據(jù)源綁定到頁面html代碼中,之前一直用組合html代碼的形式編寫,不太容易維護(hù)。Ms ajax4.0據(jù)說有一套模板引擎,只有預(yù)覽版,而且看來比較復(fù)雜,不太能馬上用。在網(wǎng)上找到一個(gè)jtemplates的js模板引擎,感覺還可以,適合用來在頁面上動(dòng)態(tài)綁定數(shù)據(jù)。
以下為引用的內(nèi)容: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>jtemplates jquery模板引擎使用-LIEHUO.NET</title> <script src="/Scripts/jquery-1.3.2.js" type="text/javascript"></script> <script src="/Scripts/plugins/jquery-jtemplates.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { var data = [{ name1: "測試信息",id:"12" },{ name1: "測試信息",id:"12" }]; $("#result").setTemplateElement("template1"); $("#result").processTemplate(data); }); </script> </head> <body> <div> <textarea id="template1" style="display: none;"> <table> <thead> <tr> <td colspan="2"> fdaasfd </td> </tr> </thead> <tbody> {#foreach $T as r} <tr> <td> name:{$T.r.name1} </td> <td> id:{$T.r.id} </td> </tr> {#/for} </tbody> <tfoot> </tfoot> </table> </textarea> </div> <div id="result"></div> </body> </html> |
轉(zhuǎn)自:http://www.cnblogs.com/ericphi/