简体   繁体   English

轨道与kaminari的无尽滚动,事件未触发

[英]rails endless scroll with kaminari, event not triggering

Fallowed the endless scrolling tutorial by Ryan Bates, and don't understand why it's not working ;/ partial does not update 支持Ryan Bates的无休止的滚动教程,并且不理解为什么它不起作用; // partial无法更新

localfeeds/show.html.erb 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 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 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 %>

Please help 请帮忙

Safari HTML render Safari HTML渲染 html渲染错误部分

localfeeds/show.js.erb localfeeds / show.js.erb

// Append new data
$('#infinite_table').append(...

but in your HTML you have: 但是在您的HTML中,您可以:

<div id="infinite-table" ....

The first uses _, the second - 第一个使用_,第二个使用-

EDIT: 编辑:

From your comments it looks like the error is in your scroll detection code. 从您的注释看来,错误出在滚动检测代码中。 Try this, and look at the console output for clues: 试试看,看看控制台输出的线索:

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()  

Which, if any, of the console log statements lead to entries in the console log? 哪个控制台日志语句(如果有)导致控制台日志中的条目? What happens when you scroll the page? 滚动页面会怎样?

Just an observation, but where is $(window).scroll() being called apart from once in the initialisation code? 只是一个观察,但是在初始化代码中,一次调用了$(window).scroll()呢?

Code creates the method if there is pagination data and then calls it once regardless - where does it get called again? 如果有分页数据,代码将创建该方法,然后无论是否调用它都将调用一次-在哪里再次调用它? Also if there is no pagination data the first call to scroll will break ... 另外,如果没有分页数据,则第一个滚动调用将中断...

I can't unpick this without more code and it might just be I have an incomplete picture. 如果没有更多代码,我将无法取消选择,可能只是我的图片不完整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM