我正在尝试制作一个电子商务列表页面,左侧栏具有不同的过滤器,右侧栏具有使用ramda和vue的产品。我有两个问题:
(1)我正在尝试将产品价格过滤为1-100。
(2)我无法对已过滤的产品进行分页。
问题1:我传递了[0,1,2,3,4,....,99,100],我试图使用“ includes()”从其中过滤掉99,但是代码无法过滤在普通的JS中应该这样做,但是我不知道ramda.js为什么只过滤确切的单词或数字。
问题2:在加载产品时,分页工作正常,但是当我进行过滤时,因为我希望每页显示10个项目;它仅在第一页显示10个项目,并丢弃所有其他已过滤的项目,因此在第一页之后没有页面。
问题1:
return R.pipe(R.pluck('product_prices'), R.uniq)(products_list)
return this.products_list.filter(
prod => (prod.product_prices].some(val => this.filters.includes(val)) )
)
问题2:
if (this.currentPage >= this.totalPages) {
this.currentPage = this.totalPages
}
var index = this.currentPage * this.itemsPerPage - this.itemsPerPage;
return this.filteredProducts.slice(index, index + this.itemsPerPage);
问题1:我想使用ramda和vue从一系列价格中过滤价格。
问题2:应用任何过滤器后,我应该能够看到所有过滤出的产品均已分页。
答案 0 :(得分:1)
问题出在这一行:
this.resultCount = (!this.activeFilters.length) ? this.products.length : this.activeFilters.length
您不想统计过滤器,但要计数过滤的产品。像这样:
this.resultCount = (!this.activeFilters.length) ? this.products.length : this.filteredProducts.length
您可以在another Fiddle中看到它。但是下次,请在此处发布您的代码。 Fiddle链接是一个不错的选择,但所有相关的内容也应出现在问题中。您发布的代码不足以证明您的问题。