gpt4 book ai didi

html - 隐藏 Rails 上 will_paginate 函数中使用的 "..."

转载 作者:行者123 更新时间:2023-11-28 15:08:29 25 4
gpt4 key购买 nike

由于值的数量,我正在使用 will_paginate,但我不知道如何隐藏“...”部分和后面的页码。这就是我目前拥有的: enter image description here

这是我想要的:

<1 2 3 4>
点击下一步会给我< 2 3 4 5 >(请注意,在两者中,我们没有看到“..”后跟 95 96 97。)

知道如何做到这一点吗?这是相关的 HTML:

<div class="pagination full">
<span class="previous_page disabled">&lt; 前へ</span>
<em class="current">1</em>
<a rel="next" href="/student/search?page=2">2</a>
<a href="/student/search?page=3">3</a>
<a href="/student/search?page=4">4</a>
<a href="/student/search?page=5">5</a>
<a href="/student/search?page=6">6</a>
<a href="/student/search?page=7">7</a>
<a href="/student/search?page=8">8</a>
<a href="/student/search?page=9">9</a>
<span class="gap">…</span>
<a href="/student/search?page=95">95</a>
<a href="/student/search?page=96">96</a>
<a href="/student/search?page=97">97</a>
<a class="next_page" rel="next" href="/student/search?page=2">次へ &gt;</a>
</div>

谢谢!

最佳答案

您需要为 will_paginate 创建一个自定义渲染器。 will_paginate 助手接受一个参数 renderer,如下所示:

<%= will_paginate(@users, :renderer => UserPaginationRenderer) %>

您只需要自己实现UserPaginationRenderer,使用您自己的规则,比如只显示 4 个链接等等。有很多关于此的信息和文章:

https://thewebfellas.com/blog/roll-your-own-pagination-links-with-will_paginate
https://www.tachyonstemplates.com/2017/custom-renderer-will-paginate/

关于html - 隐藏 Rails 上 will_paginate 函数中使用的 "...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48927734/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com