[英]rails endless scroll with kaminari, event not triggering
支持Ryan Bates的无休止的滚动教程,并且不理解为什么它不起作用; // partial无法更新
localfeeds / show.html.erb
<div class="row">
<div class="col-md-8">
<div id="infinite-table">
<%=render :partial => 'scribbles/scribbles', :locals => {:scribbles => @scribbles}%>
</div>
</div>
</div>
<%= paginate @scribbles %>
localfeeds.js.coffee
jQuery ->
if $('.pagination').length
$(window).scroll ->
url = $('.pagination .next a').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
alert("test2")
$('.pagination').text('Fetching more products...')
$.getScript(url)
$(window).scroll()
localfeeds / show.js.erb
// Append new data
$('#infinite_table').append('<%= j render(:partial => 'scribbles/scribbles', :scribbles => @scribbles) %>');
<% if (@scribbles.current_page < @scribbles.num_pages) %>
$('.pagination').replaceWith('<%= j paginate(@scribbles) %>');
<% else %>
$('.pagination').remove();
<% end %>
请帮忙
Safari HTML渲染
localfeeds / show.js.erb
// Append new data
$('#infinite_table').append(...
但是在您的HTML中,您可以:
<div id="infinite-table" ....
第一个使用_,第二个使用-
编辑:
从您的注释看来,错误出在滚动检测代码中。 试试看,看看控制台输出的线索:
jQuery ->
console.log("Creating pagination callback")
if $('.pagination').length
console.log("Pagination detected")
$(window).scroll ->
console.log("Scroll detected")
url = $('.pagination .next a').attr('href')
if url && $(window).scrollTop() > $(document).height() - $(window).height() - 50
console.log("Url found: " + url)
$('.pagination').text('Fetching more products...')
$.getScript(url)
console.log("Script loaded")
$(window).scroll()
哪个控制台日志语句(如果有)导致控制台日志中的条目? 滚动页面会怎样?
只是一个观察,但是在初始化代码中,一次调用了$(window).scroll()呢?
如果有分页数据,代码将创建该方法,然后无论是否调用它都将调用一次-在哪里再次调用它? 另外,如果没有分页数据,则第一个滚动调用将中断...
如果没有更多代码,我将无法取消选择,可能只是我的图片不完整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.