简体   繁体   中英

uncaught error on infinite scroll with kaminari Rails, why? simple

I am really new to JS so I have no idea what the source of the issue is but I am encountering what I think is a relatively simple problem. I am trying to implement an infinite scroll function like this demo here . I believe I have implemented it exactly as prescribed but I encounter the following error in Chrome Console.

'Uncaught Type Error: undefined is not a function'

which i think is what is preventing the infinite scroll from working. It seems to occur on line 3.

here is the coffeescript

$(document).ready ->
  $("#entries .pages").infinitescroll
    navSelector: "nav.pagination" 
    nextSelector: "nav.pagination a[rel=next]" 
    itemSelector: "#entries tr.photo"

rejected.js.erb

$("#entries").append("<tbody class='page'><%= escape_javascript(render(entries)) %></tbody>");

rejected.html.erb

<h1>Rejected</h1>
<table id="entries">
  <thead>
    <tr>
      <th>Name</th>
      <th>Email</th>
      <th>Photo</th>
      <th>Submitted</th>
      <th colspan="3"></th>
    </tr>
  </thead>
  <tbody class="page">
  <%= render partial: 'admin/entries/entries' %>

  </tbody>
</table>
<%= paginate entries %>

and the partial _entries.html>erb

<% if entries.any? %>
  <% entries.each do |photo| %>
    <tr id='photo_<%= photo.id %>' class='photo'>
      <td><%= photo.firstname %></td>
      <td><%= photo.email %></td>
      <td><%= image_tag photo.attachment.url %></td>
      <td><%= time_helper(photo.created_at) %></td>
      <% if photo.workflow_state == 'rejected' %>
      <td><%= link_to "Approve", (toggle_approve_field_admin_entry_path(photo, params.except(:controller, :action))), :remote => true %></td>
      <td><%= link_to 'Destroy', admin_entry_path(photo), method: :delete, data: { confirm: 'Are you sure?' }, :remote => true %></td>
      <% elsif photo.workflow_state == 'approved' %>
      <td><%= link_to "Reject", (toggle_reject_field_admin_entry_path(photo, params.except(:controller, :action))), :remote => true %></td>
      <% else %>
      <td><%= link_to "Approve", (toggle_approve_field_admin_entry_path(photo, params.except(:controller, :action))), :remote => true %></td>
      <td><%= link_to "Reject", (toggle_reject_field_admin_entry_path(photo, params.except(:controller, :action))), :remote => true %></td>
      <% end %>
    </tr>
  <% end %>
<% end %>

anybody any clues as to why this is isnt working?

UPDATE: now i dont have the error. I thin the problem is now the selector:

this in the partial, the thing that requests more

<tr id='photo_<%= photo.id %>' class='photo'>

doesn't match this matcher

itemSelector: "#entries tr.photo"

but because the id is dynamic how to a jig it in?

"Undefined is not a function" means you tried to call something that didn't exist. My bet is on that infinitescroll function; if you haven't included the infinite scroll plugin in your project (or haven't loaded it correctly), then it will be undefined and you'll get the error above. Make sure you've included the file in the correct place, and check from the browser console that the asset pipeline has included it in your page.

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