首页 > 其他分享 >js 分页拆分数据

js 分页拆分数据

时间:2023-06-08 10:13:50浏览次数:48  
标签:endIndex const 分页 pageSize js startIndex 本页 拆分 data

splitData(data, pageSize, pageNum) {
const result = [];
const pageTotal = Math.ceil(data.length / pageSize); // 计算总页数
// for (let i = 0; i < pageTotal; i++) {
// const startIndex = i * pageSize; // 计算本页数据的起始位置
// const endIndex = Math.min((i + 1) * pageSize, data.length); // 计算本页数据的结束位置
// result.push(data.slice(startIndex, endIndex)); // 将本页数据推入结果数组中
// }
const startIndex = (pageNum - 1) * pageSize; // 计算本页数据的起始位置
const endIndex = Math.min(pageNum * pageSize, data.length); // 计算本页数据的结束位置
// result.push(data.slice(startIndex, endIndex)); // 将本页数据推入结果数组中
return data.slice(startIndex, endIndex);
}

标签:endIndex,const,分页,pageSize,js,startIndex,本页,拆分,data
From: https://www.cnblogs.com/gaosj20210301/p/17465370.html

相关文章

  • go json、yaml解码
    func GetFoo(ctx context.Context) (*T, error) {  req, err := http.NewRequest("GET", "http://foo/t.json", nil)  if err != nil {    return nil, err  }  req = req.WithContext(ctx)  res, err := http.DefaultClient.Do(req)  if e......
  • 移动端预览PDF,pdf.js预览PDF文件流格式
     一开始使用了vue-pdf效果并不理想,满足不了要求还出现兼容问题,PDF.js似乎是一个完美的解决方案,号称兼容各种浏览器.快速且高效.界面按钮可以配置,而且也比原生iframe框架好看一些,但是一轮的使用下来,确确实实躺了不少的坑,特此记录一下全过程,希望以后使用的时候注意一点.以......
  • 使用THREEJS实现一个可调节档位、可摇头的电风扇
    夏天到了,用Three.js实现一个可以摇头和调节档位的电风扇。主要使用到Blender处理3D模型,用Vite+Typescript搭建项目框架。效果演示:一、处理模型1、从爱(bai)给(gei)网下载一个风扇的3D模型,在Blender中打开,给模型贴上图。2、拆解模型。将风扇模型拆解成按钮、底座、扇叶、头部......
  • JS 模拟 队列 结构
    Code:/***队列(基于动态数组)*@class*/varAQueue=(function(){/***栈容器*@type{DArray}*/letarr;/***@class*/class_AQueue{/***构造器*@constructor*@param{number}[capacity]*/con......
  • JS 中 使用 Uuid
    一、官方网站https://github.com/uuidjs/uuid二、安装uuidnpminstalluuid三、导入uuid注:官方文档里的示例只适用于服务端(nodejs),想在浏览器里使用,得换一种导入方法nodejs:import{v4asuuidv4}from'uuid';浏览器js:constuuidv4=require('uuid').v4;四、使用c......
  • Three.js系列-报错export ‘Geometry‘ (imported as ‘THREE‘) was not found in ‘
    今天遇到报错export'Geometry'(importedas'THREE')wasnotfoundin'three'port'Geometry'(importedas'THREE')wasnotfoundin'three'(possibleexports:ACESFilmicToneMapping,AddEquation,AddOpe......
  • TsVSJs之间的区别
    一、观察1.JS平常的数据类型letval;val=123;val="123";val=true;val=[1,3,5];注意点:由于JS是弱类型的,所以只要定义了一个变量,就可以往这个变量中存储任意类型的数据也正是因为如此,所以会给我们带来一个问题2.假设a是一个数组,b是一个数值functiontest......
  • 13_How to Deploy NodeJs app on Ubuntu in Production
     地址:https://www.codewithharry.com/blogpost/deploy-nodejs-app-on-ubuntu/ HowtodeployaNode.jsapplicationinproductionInthispost,wewillseehowtorunanddeployNodeJSappsinproduction.Followthestepsbelow:Step1-InstallNodejsLet�......
  • 什么是json
    a='{"pwd":"12345678","type":1}'#判断是不是一个json,可以在网上找json工具进行判断#b不是jsonb="{'pwd':'12345678','type':1}"#json表示数据为空是null,不是Nonec='{"mobile_phone":null,"pw......
  • 格式化显示JSON数据
     测试JSON{"took":1,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq......