我在标记插件上使用 jQuery 的 sortable,该插件维护与li
's 相关的对象数组,其顺序与实际项目相同。
排序完成后,我需要更新数组中项目的顺序。
我以为我只能在开始事件调用$(ui).index()
和更新事件调用中进行相同的调用,这会给我初始位置和最终位置,但两个调用都返回-1
。
我该怎么做?
结构:
<ul>
<li>here<a class="close">x</a></li>
<li>are<a class="close">x</a></li>
<li>some<a class="close">x</a></li>
<li>tags<a class="close">x</a></li>
</ul>
数组结构:
[{
label: 'here',
value: 36,
element: '$(the li that this info is about)',
index: 0
},
{
label: 'are',
value: 42,
element: '$(the li that this info is about)',
index: 1
},
{
label: 'some',
value: 21,
element: '$(the li that this info is about)',
index: 2
},
{
label: 'tags',
value: 26,
element: '$(the li that this info is about)',
index: 3
}]
JavaScript:
$('ul').sortable({
start: function(event, ui){...},
update: function(event, ui){...}
});