BaiduTemplate模板引擎使用示例(附源碼)
1、新建項目,asp.net 空Web應用程序
添加data,js,styles,templates文件夾,添加baiduTemplate.js,jquery.js,bootstrap.css
2、添加list.js腳本,代碼如下
var data = { "list": [ { "col1": "行1", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行2", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行3", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行4", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行5", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行6", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行7", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" }, { "col1": "行8", "col2": "數(shù)據(jù)2", "col3": "數(shù)據(jù)3", "col4": "數(shù)據(jù)6", "col5": "數(shù)據(jù)5", "col6": "數(shù)據(jù)6" } ] }; var template = "templates/list.html"; $.ajax({ url: template, dataType: "html", success: function (val) { $("#list").html(baidu.template(val, data)); } });
添加模板文件list.html,內容如下
<table class="table table-bordered"> <thead> <tr> <td>列1</td> <td>列2</td> <td>列3</td> <td>列4</td> <td>列5</td> <td>列6</td> </tr> </thead> <%for(var i = 0; i<list.length;i++){ var item=list[i];%> <tr> <td><%=item.col1%></td> <td><%=item.col2%></td> <td><%=item.col3%></td> <td><%=item.col4%></td> <td><%=item.col5%></td> <td><%=item.col6%></td> </tr> <%}%> </table>
3、添加default.aspx頁面,并添加引用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="baiduTemplate.Default" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> <script src="js/jquery.min.js"></script> <script src="js/baiduTemplate.js"></script> <script src="js/list.js"></script> <link href="styles/bootstrap.css" rel="stylesheet" /> </head> <body> <form id="form1" runat="server"> <div id="list" style="margin-top:10px;"> </div> </form> </body> </html>
預覽效果:
源碼下載:http://xiazai.jb51.net/201612/yuanma/baiduTemplate_jb51.rar
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持腳本之家!
相關文章
ASP.NET MVC5網站開發(fā)我的咨詢列表及添加咨詢(十二)
這篇文章主要為大家詳細介紹了ASP.NET MVC5網站開發(fā)我的咨詢列表及添加咨詢,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2015-09-09.Net WebApi消息攔截器之MessageHandler的示例
這篇文章主要介紹了.Net WebApi消息攔截器之MessageHandler的示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-08-08如何使用Python實現(xiàn)阿拉伯數(shù)字轉換成中國漢字
本文提供了一個Python代碼示例,用于將阿拉伯數(shù)字轉換為中文漢字表示,代碼定義了數(shù)字到漢字的映射表,并實現(xiàn)了處理不同位數(shù)(如個、十、百、千、萬等)的函數(shù),特別地,處理方式包括對大數(shù)字的分解和轉換,以及對連續(xù)零的特殊處理,感興趣的朋友跟隨小編一起看看吧2024-09-09在.NET中使用Newtonsoft.Json轉換,讀取,寫入的方法介紹
Newtonsoft.Json.JsonConvert類是非微軟提供的一個JSON序列化和反序列的開源免費的類庫2012-08-08