简体   繁体   中英

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

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 %>

Please help

Safari HTML render html渲染错误部分

localfeeds/show.js.erb

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

but in your HTML you have:

<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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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