簡體   English   中英

軌道與kaminari的無盡滾動,事件未觸發

[英]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渲染 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM