網(LieHuo.Net)教程 工作中需要在前端將json數據源綁定到頁面html代碼中,之前一直用組合html代碼的形式編寫,不太容易維護。Ms ajax4.0據說有一套模板引擎,只有預覽版,而且看來比較復雜,不太能馬上用。在網上找到一個jtemplates的js模板引擎,感覺還可以,適合用來在頁面上動態(tà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> |
轉自:http://www.cnblogs.com/ericphi/