/** * Created by wenhm on 2017/3/7. * json返回字段主要说明 * totalHits 命中数量 * dretitle 标红标题 * docDate 文档时间 * dreDate 稿件发布时间 * pageSize 每页显示条数 * page 当前页码 * myValues 自定义显示字段(按照实施需要显示字段) ,默认为空 * */ var url; //var websiteId;//站点id var channelId;//栏目id //var parentId;//父栏目id var pageSize;//每页显示条数 var titleNum=''; var html = ''; var jsonObj = ''; $(function () { //获取栏目id url = document.location.href.toString(); //html = $(".colList").html(); //websiteId=$("#websiteId").val(); channelId=$("#channelId").val(); //parentId=$("#parentId").val(); pageSize=$("#pageSize").val(); titleNum=$("#titleNum").val(); // getJSON(1); }); // $(function () { //获取栏目id // url = document.location.href.toString(); // var str = url.substring(url.indexOf("?")+1,url.length); // var strs = str.split("&"); // html = $("#colList").html(); // for(var i=0;i=0){ // websiteId=a.substring(a.indexOf("=")+1);//站点id // } // if(a.indexOf("channelId")>=0){ // channelId=a.substring(a.indexOf("=")+1);//栏目id // } // if(a.indexOf("parentId")>=0){ // parentId=a.substring(a.indexOf("=")+1);//父栏目id // } // if(a.indexOf("pageSize")>=0){ // pageSize=a.substring(a.indexOf("=")+1);//每页显示条数 // } // } // getJSON(1); // }); //获取json数据 渲染列表 function getJSON1(_channelId,_qt,page,_isPage,_class){ var channelIds=_channelId; if(jsonObj == ""){ //alert("jinru if fangwen test.json"); $.ajax({ url:'/zfxxgk/json/test.json', type: 'get', dataType: 'json', success:function(msg){ jsonObj = msg.data; //数组channelId //getJSON(channelId,"",1,0); //默认显示分页 for (var i=0;i conf.pages){ conf.groups = conf.pages; } //计算当前组 dict.index = Math.ceil((conf.curr + ((conf.groups > 1 && conf.groups !== conf.pages) ? 1 : 0))/(conf.groups === 0 ? 1 : conf.groups)); //当前页非首页,则输出上一页 if(conf.curr > 1 && conf.prev){ view.push(''+ conf.prev +''); } //当前组非首组,则输出首页 if(dict.index > 1 && conf.first && conf.groups !== 0){ view.push(''+ conf.first +''); } //输出当前页组 dict.poor = Math.floor((conf.groups-1)/2); dict.start = dict.index > 1 ? conf.curr - dict.poor : 1; dict.end = dict.index > 1 ? (function(){ var max = conf.curr + (conf.groups - dict.poor - 1); return max > conf.pages ? conf.pages : max; }()) : conf.groups; if(dict.end - dict.start < conf.groups - 1){ //最后一组状态 dict.start = dict.end - conf.groups + 1; } for(; dict.start <= dict.end; dict.start++){ if(dict.start === conf.curr){ view.push(''+ dict.start +''); } else { view.push(''+ dict.start +''); } } //总页数大于连续分页数,且当前组最大页小于总页,输出尾页 if(conf.pages > conf.groups && dict.end < conf.pages && conf.last && conf.groups !== 0){ view.push(''+ conf.last +''); } //当前页不为尾页时,输出下一页 dict.flow = !conf.prev && conf.groups === 0; if(conf.curr !== conf.pages && conf.next || dict.flow){ view.push((function(){ return (dict.flow && conf.curr === conf.pages) ? ''+ conf.next +'' : ''+ conf.next +''; }())); } return '
'+ view.join('') + function(){ return conf.skip ? '' + '' : ''; }() +'
'; }; //跳页 Page.prototype.jump = function(elem){ if(!elem) return; var that = this, conf = that.config, childs = elem.children; var btn = elem[tag]('button')[0]; var input = elem[tag]('input')[0]; for(var i = 0, len = childs.length; i < len; i++){ if(childs[i].nodeName.toLowerCase() === 'a'){ Page.on(childs[i], 'click', function(){ var curr = this.getAttribute('data-page')|0; conf.curr = curr; that.render(); }); } } if(btn){ Page.on(btn, 'click', function(){ var curr = input.value.replace(/\s|\D/g, '')|0; if(curr && curr <= conf.pages){ conf.curr = curr; that.render(); } }); } }; //渲染分页 Page.prototype.render = function(load){ var that = this, conf = that.config, type = that.type(); var view = that.view(); if(type === 2){ conf.cont.innerHTML = view; } else if(type === 3){ conf.cont.html(view); } else { doc[id](conf.cont).innerHTML = view; } conf.jump && conf.jump(conf, load); that.jump(doc[id]('laypage_' + conf.item)); if(conf.hash && !load){ location.hash = '!'+ conf.hash +'='+ conf.curr; } }; //for 页面模块加载、Node.js运用、页面普通应用 "function" === typeof define ? define(function() { return laypage; }) : "undefined" != typeof exports ? module.exports = laypage : window.laypage = laypage; }();