Sequelize分页 -针对拼接数组进行封装

代码流程

1. 数组1查询
    const AllTourGuide = await this._TourGuide.findAll({
      include: this._getAssociationOptionsForTime()
    })
    let arr = []
    for (let leave of AllTourGuide) {
      if (leave.tour_guide_leaves.length === 0) {
        arr.push(leave)
      }
    }

arr数组

2. 数组2查询
    let where = { attractionId }
    let include = null
    if (Time) {
      include = this._getAssociationOptionForTime(Time)
    } else {
      include = this._getAssociationOptionsForTime()
    }
    const options = {
      where,
      include
    }
    const leaveGuide = await this._TourGuide.findAll(options)
3.返回数组1,数组2 并对返回的数组分页
 return this.getpaging(currentPage, Count, result)
  }

  getpaging (currentPage, count, result) {
    return result.slice((currentPage - 1) * count, currentPage * count)
  }
4. slice(start,end):返回从原数组中指定开始下标到结束下标之间的项组成的新数组

result.slice((currentPage - 1) * count, currentPage * count)

sequlize相关 https://www.jianshu.com/p/84f65edf4174

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值