廢話不多說了,下面跟大家分享react.js翻頁插件的程式碼,具體程式碼如下:
var Page = React.createClass({ render:function() { //中间代码更新 var totalRows = this.props.totalRows; var listRows = this.props.listRows; var nowPage = this.props.nowPage>0?this.props.nowPage:1; var firstRow = this.props.listRows*(this.props.nowPage-1); var totalPage = Math.ceil(totalRows/listRows); var show_count=this.props.show_count?this.props.show_count:5; if((!totalPage)&&nowPage>totalPage) { this.props.nowPage=totalPage; } if(this.props.nowPage<1) { this.props.nowPage=1; } var show_count_mid=show_count/2; var pages = []; for(var i=1;i<=show_count;i++) { var page=0; if(nowPage<=show_count_mid) { page = i; } else if(nowPage+show_count_mid>totalPage) { page = totalPage - show_count+i; } else { page =nowPage-Math.ceil(show_count_mid)+i; } if(page>0&&page!=nowPage) { if(page<=totalPage) { pages.push(<li onClick={this.props.onPagination.bind(this,page)}><a>{page}</a></li>); } } else { pages.push(<li className="active"><a>{page}</a></li>); } } this.pagesbutton=pages; return ( this.props.totalRows>0?( <ul className="pagination"> <li><a>Total:{this.props.totalRows} {this.props.nowPage}/{Math.ceil(this.props.totalRows/this.props.listRows)}</a></li> <li onClick={this.props.onPagination.bind(this,1)}><a>firstpage</a></li> <li onClick={this.props.onPagination.bind(this,this.props.nowPage==1?1:this.props.nowPage-1)}><a href="#none">«</a></li> {this.pagesbutton} <li onClick={this.props.onPagination.bind(this,this.props.nowPage==this.props.totalPage?this.props.totalPage:this.props.nowPage+1)}> <a href="#none">»</a> </li> <li onClick={this.props.onPagination.bind(this,Math.ceil(this.props.totalRows/this.props.listRows))}><a>lastpage</a></li> </ul> ):( <ul className="pagination"> <li><a>No data</a></li> </ul> ) ); } });
以上所述是小編給大家介紹的react.js 翻頁外掛程式實例程式碼,希望對大家有幫助,如果大家有任何疑問請給我留言,小編會及時回覆大家的。在此也非常感謝大家對PHP中文網的支持!
更多react.js 翻頁插件實例代碼相關文章請關注PHP中文網!