繁体   English   中英

用kaminari Rails进行无限滚动时出现未捕获的错误,为什么? 简单

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

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

有人对这为什么不起作用有任何线索吗?

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

这部分,要求更多的东西

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

与该匹配器不匹配

itemSelector: "#entries tr.photo"

但是由于id是动态的,如何将其插入?

“未定义不是函数”表示您试图调用不存在的内容。 我敢打赌,这个infinitescroll功能; 如果您没有在项目中包含无限滚动插件 (或尚未正确加载),那么它将是未定义的,并且会收到上面的错误。 确保已将文件包含在正确的位置,然后从浏览器控制台检查资产管道已将其包含在页面中。

暂无
暂无

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

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