laypage加laytpl的使用方法,技术不好,摸索了好久才弄出来。
首先去layer官网下载这两个插件,按照他们的文档引入js
然后我的代码如下:
1:html+jquery<div><!--这是循环获取的数据--></div>
<br>
<br>
//laypage paging<br>
Ajaxpage();<br>
function Ajaxpage(curr,num){<br>
If(!num){<br>
Num=5;
};<br>
var catid=$('#catid').val(); //This is the conditional selection column id<br>
var starttime=$('#starttime').val();//This is the conditional filtering start time<br>
var endtime=$('#endtime').val();//This is the end time of conditional filtering<br>
var title=$('#title').val();//This is the title keyword<br>
$.get('{:U("Content/article")}', {<br>
Page: curr || 1,num:num,catid:catid,starttime:starttime,endtime:endtime,title:title<br>
}, function(data){<br>
//This paragraph is the assignment of template rendering of laytpl<br>
var tpl = document.getElementById('arlist').innerHTML; //Define tpl <script id="arlist" type="text/html"></script> <br>
Laytpl (tpl). Rreater (data.info.lists, function (html) {// pass the obtained JSON data to it
document.getElementById('article_list').innerHTML = //This is to get the data, and then render it into the div with the id of article_list<br>
});<br>
cont: $('#AjaxPage'), <br>
pages:data.info.allpage, <br>
Skip: true,<br>
Skin: '#23c6c8',<br>
curr: curr || 1,<br>
groups: 3,<br>
jump: function(obj, first){<br>
if(!first){<br>
Ajaxpage(obj.curr,num) <br>
}<br>
}<br>
});<br>
});<br>
}<br>
//This is the js template of tpl. I deleted some of the same parts and left the different ones. There is also the use of if tags, but I don’t know how to use the U method here, so I used the jquery method to call it. Some features <br>
<script id="arlist" type="text/html"><br />
{{# for(var i=0;i<d.length;i++){ var vo=d[i] }} //This is the for loop in js, just use the tpl template tag {{# } } Contains <br />
<td style="text-align:center">{{vo.views}}<br />
<td style="text-align:center">{{vo.author}}<br />
<td style="text-align:center">{{vo.uptime}}<br />
<td style="text-align:center"><br />
{{# if(vo.status==1){ }} <br />
<a class="label label-info" href="javascript:;" onclick="return ar_status(this,'status_{{vo.id}}_0');">审核<br />
{{# }else{ }}<br />
<a class="label label-danger" href="javascript:;" onclick="return ar_status(this,'status_{{vo.id}}_1');">审核<br />
{{# } }}<br />
<br />
<td style="text-align:center"><br />
<div class="btn-group"><br />
<a data-toggle="dropdown" class="label label-info dropdown-toggle">文章操作 <span class="caret"><br />
<ul class="dropdown-menu"><br />
<li><a href="javascript:ar_edit({{vo.id}})" class="font-bold">修改 <br />
<li class="divider"><br />
<li><a href="javascript:ar_del({{vo.id}})" class="J_del">删除<br />
<br />
<br />
{{# }; }}<br />
</script><br>2:php<br>//Article list
Public function article(){
If($_GET['page']){<br>
$Nowpage = $_GET['page']?$_GET['page']:1; //Get the current page<br>
$catid=intval($_GET['catid']);//Get conditional filter column id<br>
$starttime=strtotime($_GET['starttime']);//Conditional filtering start time<br>
$endtime=strtotime($_GET['endtime']);//Conditional filtering end time<br>
$title=$_GET['title'];//Conditional filtering keywords<br>
$map="id>0";//Combined query conditions<br>
if($catid>0){<br>
$map.=" and catid=".$catid."";
}<br>
if(!empty($starttime)){<br>
$map.=" and uptime>=".$starttime." and uptime
if(!empty($endtime)){<br>
$map.=" and uptime>=".$starttime." and uptime
}<br>
if(!empty($title)){<br>
$map.=" and title like '%$title%'";<br>
}<br>
$limits = $_GET['num']?$_GET['num']:5; // 5 pieces of data are queried here by default<br>
// Get the total number of items <br>
$count = M('Article')->where($map)->count();<br>
//Calculate total pages<br>
$allpage = ceil($count / $limits);<br>
$allpage = intval($allpage);<br>
$lists = M('Article')->where($map)->page($Nowpage, $limits)-> order('listorder asc')-> select();<br>
foreach($lists as $k=>$v){<br>
$lists[$k]['catname']=catname($v['catid']);//This is the method I wrote to get the current column name<br>
$lists[$k]['uptime']=friendlyDate($v['uptime']);//This is the method I wrote to get the time<br>
}<br>
$data['allpage']=$allpage;//Return the total number of pages<br>
$data['lists']=$lists;//Query data list<br> $this->success($data);exit;<br>
}<br>
$cate=M('Category')->order('listorder ASC')->select();<br>
$this->assign('catelist',$cate);<br>
$this->display();<br>
}
Page made by me
If you have any questions, please contact me: QQ 3126620990 My website: http://www.renweinet.net
http://www.hjlog.net

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.
