queryString: function (key, val) { var query = this.route.query; if (typeof val === 'undefined') return query[key]; if (query[key] == val) return; else if (val === null || val === false || val === '') delete query[key]; else query[key] = val; var queryString = $.param(query); this.route.url = this.url = this.route.path + (queryString ? '?' + queryString : ''); this.application.navigate(this.url); var data = {}; data[key] = val; this.trigger(new Event('QueryChange', { data: data })); }
var objectToParams = function (obj, decodeUri) { var param = $.param(obj); if (decodeUri) { param = decodeURIComponent(param); } return param; };
view: function(flag) { var isPost = this.get('method').toLowerCase() === 'post'; var url = this.get('url'); var x = this.get('x') || 2; // 当前页码附近显示页数 var y = this.get('y') || 1; // 省略号附近显示页数 var size = this.get('size'); var totalPage = Math.ceil(this.get('total') / size); // 总页数 var current = this.get('current'); // 当前页 var sizeName = this.get('sizeName'); var pageName = this.get('pageName'); var html = []; var pn = ['', '']; var split = '<span>...</span>'; var i; if(!isPost) { url += url.indexOf('?') === -1 ? '?' : '&'; url += $.param(this.get('data') || {}); if(url.indexOf(sizeName + '=') === -1) { url += sizeName + '=' + size + '&'; } if(url.indexOf(pageName + '=') === -1) { url += pageName + '='; } } if(this.get('showPN') !== false) { pn[0] = '<a href="' + (isPost ? '#' : (url + Math.max(1, current - 1))) + '" data-action="prev">上一页</a>'; pn[1] = '<a href="' + (isPost ? '#' : (url + Math.min(totalPage, current + 1))) + '" data-action="next">下一页</a>'; } if(totalPage <= 5) { for(i = 1; i <= totalPage; i++) { html.push(helper.tpl(url, i, isPost)); } } else { if(current <= 3) { for(i = 1; i <= 4; i++) { html.push(helper.tpl(url, i, isPost)); } html.push(split, helper.tpl(url, totalPage, isPost)); } else if(current >= totalPage - 2) { html.push(helper.tpl(url, 1, isPost), split); for(i = totalPage - 2; i <= totalPage; i++) { html.push(helper.tpl(url, i, isPost)); } } else { html.push(helper.tpl(url, 1, isPost), split, helper.tpl(url, current - 1, isPost), helper.tpl(url, current, isPost), helper.tpl(url, current + 1, isPost), split, helper.tpl(url, totalPage, isPost)); } } this.element.html(pn[0] + html.join('') + pn[1]); this.reflow(); if(this.get('type') === 'ajax') { if(flag !== false) { this.ajax(); } } else { this.get('success') && this.get('success').call(this, current, $.isArray(this.get('data')) ? this.get('data').splice((current - 1) * size, Math.min(this.get('data').length, current * size)) : []); } return this; },
queryString: function (key, val) { if (typeof val === 'undefined') return this.route.query[key]; else if (val === null || val === false || val === '') delete this.route.query[key]; else this.route.query[key] = val || ''; var query = $.param(this.route.query); this.application.navigate(this.route.path + (query ? '?' + query : '')); },