【发布时间】:2014-06-17 21:09:36
【问题描述】:
我使用 jQuery 制作了一个可排序的表格,请参阅:https://www.youtube.com/watch?v=bRbl2ey9gt4
我需要它以新顺序发布项目的位置。
目前其发布的是空值,见下文:
Started POST "/episodes/sort" for 127.0.0.1 at 2014-06-17 16:30:44 -0400
Processing by EpisodesController#sort as */*
Parameters: {"episodes"=>["", "", "", "", "", "", "", ""]}
我知道我必须使用 content_tag,但我不理解它背后的逻辑,因为我使用的是 html 表。
这是我的看法:
管理剧集
<tbody id='eps'>
<tr>
<th>Title</th>
<th>#</th>
<th>Season</th>
<th>Download?</th>
<th>Shared?</th>
<th>Length</th>
<th>Status</th>
<th></th>
</tr>
<% for episode in @episodes %>
<tr>
<td width="20%"><%=h episode.title %></td>
<td><%=h episode.number %></td>
<td><%=h episode.season %></td>
<td><%=h episode.is_downloadable %></td>
<td><%=h episode.shared_with_dev %></td>
<td><%=h episode.length %></td>
<td>
排除不必要的东西。
这是我的 JS:
$(window).load(function() {
$("#eps").sortable({
// Maintains width when being sorted
helper: function(e, tr){
var $originals = tr.children();
var $helper = tr.clone();
$helper.children().each(function(index){
$(this).width($originals.eq(index).width())
});
return $helper;
},
axis: 'y',
placeholder: 'ui-state-highlight',
cursor: 'move',
dropOnempty: false,
scroll: true,
opacity: 0.4,
tolerance: 'pointer',
revert: 'true',
update: function(event, ui){
var itm_arr = $("#eps").sortable('toArray');
var pobj = {episodes: itm_arr};
$.post("/episodes/sort", pobj);
}
});
});
谢谢
【问题讨论】:
标签: javascript jquery ruby-on-rails jquery-ui