Skip to content

Instantly share code, notes, and snippets.

@shau-lok
Last active August 24, 2023 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shau-lok/add3a95f670b33d6b2c708be925205a5 to your computer and use it in GitHub Desktop.
Save shau-lok/add3a95f670b33d6b2c708be925205a5 to your computer and use it in GitHub Desktop.
后端返回所有数据, 前端做分页
// 前端做数据分页
function pagination(pageNo, pageSize, array) {
var offset = (pageNo - 1) * pageSize;
return (offset + pageSize >= array.length) ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize);
}
// 后端django做分页
from django.core.paginator import Paginator
samples = sample.objects.filter(Q()).order_by('id').values()
pagination = Paginator(samples, page_size)
page = pagination.page(page_num)
page = list(page.object_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment