javascript - jQuery 可排序问题

标签 javascript jquery coffeescript

在我的用户/索引 View 中保存无序列表

<ul id="documents" data-update-url="<%= sort_documents_url %>">
  <% @documents.each do |document| %>
  <%= content_tag_for :li, document do %>
  <span class="handle">[drag]</span>
  <%= link_to h(document.title), document %>
  <%= link_to 'Delete', document, method: :delete, remote: true %>
  <% end %>
  <% end %>
</ul>

正如您在 ul 中看到的那样,我正在为每个模型渲染部分内容。 _documents.html.erb 部分 渲染 html 的第二次更新。

<ul id="documents" data-update-url="http://localhost:3000/documents/sort">
  <li class="document" id="document_4fc4db0cb6231417f300000c">
    <span class="handle">[drag]</span>
    <a href="/documents/4fc4db0cb6231417f300000c">Help</a>
    <a href="/documents/4fc4db0cb6231417f300000c" data-method="delete" data-remote="true" rel="nofollow">Delete</a>
</li>  <li class="document" id="document_4fc4db27b6231417f300000f">
    <span class="handle">[drag]</span>
    <a href="/documents/4fc4db27b6231417f300000f">adam</a>
    <a href="/documents/4fc4db27b6231417f300000f" data-method="delete" data-remote="true" rel="nofollow">Delete</a>
</li>  <li class="document" id="document_4fc4db2db6231417f3000010">
    <span class="handle">[drag]</span>
    <a href="/documents/4fc4db2db6231417f3000010">adam</a>
    <a href="/documents/4fc4db2db6231417f3000010" data-method="delete" data-remote="true" rel="nofollow">Delete</a>
</li>  <li class="document" id="document_4fc4dbaab6231417f3000015">
    <span class="handle">[drag]</span>
    <a href="/documents/4fc4dbaab6231417f3000015"></a>
    <a href="/documents/4fc4dbaab6231417f3000015" data-method="delete" data-remote="true" rel="nofollow">Delete</a>
</li></ul>

document.js.coffee jQuery->

  $('#documents').sortable
    handle: '.handle'
    update: ->
      $.post($(this).data('update-url'), $(this).sortable('serialize'))

最佳答案

您不能拥有 <div>直接下一个<ul> 。我敢打赌这会破坏脚本。

事实上,you cannot have anything other than <li> inside a <ol> or <ul> .

关于javascript - jQuery 可排序问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10798895/

相关文章:

javascript - HighCharts 子弹图标签显示在顶部 可能吗?

javascript - jQuery 检测 PHP 页面加载时输入的变化

javascript - 在 Javascript 不工作的情况下点击显示/隐藏

javascript - 如何修复 jquery 库中的 'jQuery is not defined' 错误?

javascript - 不使用网格的贪吃蛇游戏算法,段的移动速度可能比它们的尺寸慢

javascript - 如何使用 "in"和/或 "hasOwnProperty"缩小对象类型

Javascript、倒数计时器和显示文本

coffeescript - 如何在 CoffeeScript 中缩进列表理解?

javascript - 有没有办法在 TestComplete 中自动格式化(Javascript)代码?

javascript - Rails - 如何在 View 中访问 Google map 实例?