首页 > 代码库 > MVC - 11(下).jquery.tmpl.js 接收JSON类型数据循环
MVC - 11(下).jquery.tmpl.js 接收JSON类型数据循环
继续 mvc-11(上).dto:http://www.cnblogs.com/tangge/p/3840060.html
jquery.tmpl.js 下载:http://pan.baidu.com/s/1o68w7Ke
1.前台
Index.cshtml
@{ ViewBag.Title = "学员列表";}@section headSection{ <script type="text/x-jquery-tmpl" id="trtemp"> <tr> <th>${StudentID}</th> <th>${Cid}</th> <th>${Name}</th> <th>${Gender}</th> <th>操作</th> </tr> </script> <script type="text/javascript"> $(function () { //0.关闭Jquery的浏览器缓存 $.ajaxSetup({ cache: false }); loadPageList(1); }); //根据页码 异步请求数据 function loadPageList(pageIndex) { $.get("/Stu/List/" + pageIndex, null, function (jsonData) { if (jsonData.Statu=="OK") { //alert(jsonData.Msg); $("#trtemp").tmpl(jsonData.Data.PageData).appendTo("#tableList"); } alert(jsonData.msg); },"json"); } </script>}<table id="tableList" border="1" cellspacing="0" cellpadding="0" width="100%"> <tr> <th>ID</th> <th>班级名</th> <th>姓名</th> <th>性别</th> <th>操作</th> </tr></table>
但是要报错
TypeError: $(...).tmpl is not a function
$("#trtemp").tmpl(jsonData.Data.PageData).appendTo("#tableList");
找了半天原因,结果查看页面源代码
这里,在_Layout.cshtml里面,引入juqey和tmpl,然后注释调
@Scripts.Render("~/bundles/jquery")
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。