【发布时间】:2013-04-13 15:01:26
【问题描述】:
我正在尝试在我的项目中实现无限滚动。 我已经按照这个方法做了所有事情:https://github.com/amatsuda/kaminari/wiki/How-To:-Create-Infinite-Scrolling-with-jQuery 但这对我不起作用:(
控制器:
def show
category = Category.find(params[:id])
products = category.products.page(params[:page])
@category = CategoryDecorator.decorate(category)
@products = ProductDecorator.decorate_collection(products)
respond_to do |format|
format.js
format.html
format.xml { render :xml => @products }
end
end
show.html.haml:
#products_list
%page
= render 'products_list'
:javascript
$(function() {
var page = 1,
loading = false;
function nearBottomOfPage() {
return $(window).scrollTop() > $(document).height() - $(window).height() - 200;
}
$(window).scroll(function(){
if (loading) {
return;
}
if(nearBottomOfPage()) {
loading=true;
page++;
$.ajax({
url: '/universes/nautique/sports/surfwear/categories/boarshorts?per_page=' + page,
type: 'get',
dataType: 'script',
success: function() {
$(window).sausage('draw');
loading=false;
}
});
}
});
$(window).sausage();
}());
- content_for :javascript do
= javascript_include_tag "jquery.sausage"
部分_products_list.html.haml:
- @products.each_with_index do |product,index|
.block-prodlist{ data: { index: product.id } }
.inner.onfocus
.selection
%label AJOUTER À MA SÉLECTION
%input.chk{:name => "", :type => "checkbox", :value => ""}/
.thumbproduit
= index
%img{:alt => "Produit", :height => "194", :src => "/assets/editorial/produit1.jpg", :width => "194"}/
.prixcaption -20%
.context
%h3
= product.brand_name
还有show.js.haml:
$("#products_list").append("#{escape_javascript(render(@products))}");
我的 firebug 中没有看到 show.js。
【问题讨论】:
-
/;It's not working or me"。它怎么不工作(除了不滚动,我的意思是你到底看到了什么)。你在 javascript 控制台中看到错误吗?
-
您需要了解 javscript 控制台和使用 Web 开发人员工具,才能使用这些东西。 (此类工具的)实际实现取决于您的浏览器。我认识的最优秀的开发者这些天都在使用 Chrome。有助于解释为什么它的市场份额在短短 4 年内从 0% 上升到 50%!
标签: ruby-on-rails-3 haml infinite-scroll kaminari