Rails Spree Kaminari无限滚动产品页面
我尝试使用本教程Kaminari无尽的页面 ,并观看了Ryan Bates 第114集“ 无尽页面”(修订版),并试图在我的在线商店实现无限滚动function。
我不确定如何在我的index.js.erb文件中应用产品渲染,因为它在Spree中实现的完全不同。 我也忘了提到我对Spree平台很新。
到目前为止我所做的一切都是改变这些文件:
意见/大礼包/产品/ index.html的
'spree/shared/filters' %> 'spree/shared/taxonomies' %> 'spree/shared/products', :locals => { :products => @products, :taxon => @taxon } %> 'spree/shared/products', :locals => { :products => @products, :taxon => @taxon } %>
意见/大礼包/产品/ index.js.erb的
$("#home-products").append(' 'spree/shared/products', :locals => { :products => @products, :taxon => @taxon }) %>'); $('.pagination').replaceWith(''); $('.pagination').remove();
这是部分视图/ spree / shared / _products.html.erb
h(params[:keywords])) %>
<li id="product_" class="columns three "classes") %>" data-hook="products_list_item" itemscope itemtype="http://schema.org/Product"> "image"), product, :itemprop => 'url' %> 50), product, :class => 'info', :itemprop => "name", :title => product.name %>
资产/ Java脚本/存储/ products.js.coffee
jQuery -> if $('.pagination').length $(window).scroll -> url = $('.pagination .next').attr('href') if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50 $('.pagination').text("Fetching more products...") $.getScript(url) $(window).scroll()
根据Ryan的一些评论,我在这里只将’.next_page’改为’.next’。
我很确定这个问题与partial有关,因为它不是直接渲染产品,但我不知道如何更改它以便它可以工作。
谁能帮我这个? 谢谢。
看起来我没有渲染正确的部分
解决我问题的内容是:
视图/礼包/产品/ index.js.erb的
<%= render 'spree/shared/products.js.erb' %>
我还为产品创建了一个新的js partial,因为那是我实际上应该进行分页的地方。
视图/礼包/共享/ _products.js.erb
$('ul#products').append('<%= j render(:partial => 'spree/shared/product', :collection => @products) %>'); <% if @products.current_page < @products.total_pages %> $('.pagination').replaceWith('<%= j paginate @products %>') BWLD.can_scroll = true <% else %> $('.pagination').remove(); <% end %>