Skip to content

Instantly share code, notes, and snippets.

@zzjtnb
Last active August 9, 2020 07:27
Show Gist options
  • Select an option

  • Save zzjtnb/3b07f77bf1b4a4c789855577b70fc7bd to your computer and use it in GitHub Desktop.

Select an option

Save zzjtnb/3b07f77bf1b4a4c789855577b70fc7bd to your computer and use it in GitHub Desktop.
利用数组制作分页效果
# 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