我使用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);
}
});
});
谢谢
答案 0 :(得分:0)
您需要tr
s来获取jQuery UI sortable toArray
的属性。
The documentation indicates id
is used by default
尝试
<tr id="<%= episode.id %>">