使用jQuery分页插件进行分页 [英] pagination using jquery pagination plugin

查看:66
本文介绍了使用jQuery分页插件进行分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在了解jQuery Pagination插件时遇到了一些问题.这是我第一次使用它.在我的上一个问题上,一个人为我提供了此解决方案,但我只是无法使其对我有用.我不明白为什么每个隔壁房间都进入上一个房间.这是图片

I'm having a bit of an issue understanding the jQuery Pagination plugin. This is my first time using it. On my prev question one guy offered me this solution, but I just can't make it work for me; I don't understand why each next room goes inside the previous one. Here is a pic

function __createRoomCard(data) {
  for (var i = 0, len = data.length; i < len; i++) {
    data[i] = `<div class="rooms__item-wrapper" id="rooms__item-wrapper">
        <picture><img class="rooms__image" src="img/${data[i].img}" alt="Room image"></picture>
        <ul class="rooms__item">
        <li><h2 class="rooms__item-heading">${data[i].name}</h2></li>
        <li class="rooms__item-description"><p class="rooms__item-description--list">
        <sup class="rooms__item-description--dollar">$</sup>
        <span class="rooms__item-price">${data[i].price}</span><sub>/per night</sub></p></li>
        </ul>`;
  }
  return data.join("");
}

$(document).ready(function() {
  DATA_SOURCE = [{
    img: 'rooms_img_1.jpg',
    price: 125,
    name: 'Single Room'
  }, {
    img: 'rooms_img_2.jpg',
    price: 240,
    name: 'Standart Room'
  }, {
    img: 'rooms_img_3.jpg',
    price: 325,
    name: 'Double Room'
  }, {
    img: 'rooms_img_4.jpg',
    price: 450,
    name: 'Family Room'
  }, {
    img: 'rooms_img_5.jpg',
    price: 500,
    name: 'VIP Room'
  }, {
    img: 'rooms_img_6.jpg',
    price: 600,
    name: 'Suite'
  }]

  $('#list').pagination({
    dataSource: DATA_SOURCE,
    pageSize: 3, //here put number of items per page
    callback: function(data, pagination) {
      // template method of yourself
      var html = __createRoomCard(data);
      $('#Z').html(html);
    }
  })
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://pagination.js.org/dist/2.1.5/pagination.min.js"></script>
<div id="Z">Loading...</div>
<div id="list"></div>

推荐答案

我的朋友,请在 data [i] 的末尾添加</div>

hi my friend please add </div> at the end of data[i] like this

</ul></div>

这篇关于使用jQuery分页插件进行分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆