Last active
August 9, 2020 07:27
-
-
Save zzjtnb/3b07f77bf1b4a4c789855577b70fc7bd 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
| # js | |
| ```JavaScript | |
| let arr= [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] | |
| function pagination (currentPage, pageSize, array) { | |
| const skipNum = (currentPage - 1) * pageSize; | |
| return (skipNum + pageSize >= array.length) ? array.slice(skipNum, array.length) : array.slice(skipNum, skipNum + pageSize) | |
| } | |
| console.log(pagination(2,4,arr)) | |
| ``` | |
| # ts | |
| ```ts | |
| /** | |
| * 利用数组制作分页效果 | |
| * @param {Number} currentPage 当前的页数 | |
| * @param {Number} pageSize 一页的总数 | |
| * @param {Array} array 待分页的数组 | |
| * @return {Array} newArr 分页后的数组 | |
| */ | |
| exports.pagination = function (currentPage, pageSize, array) { | |
| // skipNum:跳过的数量 | |
| const skipNum = (currentPage - 1) * pageSize; | |
| return (skipNum + pageSize >= array.length) ? array.slice(skipNum, array.length) : array.slice(skipNum, skipNum + pageSize) | |
| } | |
| // module.exports = { | |
| // pagination | |
| // } | |
| ``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment