// Pagination source code ==============================================================
const [currentPage, setCurrentPage] = useState(1)
const [postsPerPage] = useState(6)
const indexOfLastPost = currentPage * postsPerPage;
const indexOfFirstPost = indexOfLastPost - postsPerPage;
const currentPosts = moviedata.slice(indexOfFirstPost, indexOfLastPost)
const howManyPages = Math.ceil(moviedata.length/postsPerPage)
<div className='movieslist'>
<div className='list'>
{currentPosts.filter(u=>u.title.toLocaleLowerCase().includes(query)).map((fd, i) => {
return <Card img={fd.img} title={fd.title} quality={fd.quality} rating={fd.rating} price={fd.price} duration={fd.duration} year={fd.year} id={fd.id} allproduct={fd} allwishlist={fd} key={i} />
})}
</div>
<Pagination pages = {howManyPages} setCurrentPage={setCurrentPage}/>
</div>
- 我想搜索所有页面的项目,而不仅仅是一个页面****但它只搜索一个页面上的项目**
1条答案
按热度按时间nwo49xxi1#
1)
乍一看,您似乎在过滤
currentPosts
如果你想搜索所有页面的条目,你应该过滤
moviedata
,而不是在过滤之前切片2)
当然,它可能需要一点重建其他部分,如果你需要帮助,让我知道!
3)如何重建
如果你的过滤器经常应用,它应该可以解决你的问题
请注意
someString.includes('') // always returns true
如果查询为空,则将获取所有数据