Last active
August 24, 2023 00:36
-
-
Save shau-lok/add3a95f670b33d6b2c708be925205a5 to your computer and use it in GitHub Desktop.
后端返回所有数据, 前端做分页
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 前端做数据分页 | |
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