未捕获的错误无限卷轴与kaminari Rails,为什么?简单



我真的是新的JS,所以我不知道问题的来源是什么,但我遇到了我认为是一个相对简单的问题。我想实现一个无限滚动函数,就像这个演示一样。我相信我已经完全按照规定实现了它,但我在Chrome控制台遇到以下错误。

'Uncaught Type Error: undefined is not a function'

我认为这是阻止无限滚动工作的原因。似乎发生在第3行。

这是咖啡脚本

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

和部分_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 %>
有谁知道为什么这不起作用吗?

更新:现在我没有错误。我认为现在的问题是选择器:

this在partial中,请求更多

的东西
<tr id='photo_<%= photo.id %>' class='photo'>

不匹配这个匹配器

itemSelector: "#entries tr.photo"

但是因为id是动态的,如何将其插入?

"Undefined is not a function"意味着你试图调用不存在的东西。我赌的是infinitescroll函数;如果你没有在你的项目中包含无限滚动插件(或者没有正确加载它),那么它将是未定义的,你会得到上面的错误。确保将文件包含在正确的位置,并从浏览器控制台中检查资产管道是否已将其包含在页面中。

最新更新