Hai*_*ood 20 jquery jquery-ui jquery-ui-sortable
我在标记插件上使用jQuery的可排序,该插件维护一个与li
实际项目顺序相关的对象数组.
我需要在排序完成时更新数组中项目的顺序.
我以为我能够在启动事件调用$(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>
Run Code Online (Sandbox Code Playgroud)
数组结构:
[{
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
}]
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
$('ul').sortable({
start: function(event, ui){...},
update: function(event, ui){...}
});
Run Code Online (Sandbox Code Playgroud)
sid*_*rcy 32
$(function() { $( "#sortable" ).sortable({ update: function(event, ui) { console.log('update: '+ui.item.index()) }, start: function(event, ui) { console.log('start: ' + ui.item.index()) } }); $( "#sortable" ).disableSelection(); });
Bra*_*vij 12
如果 .index()
返回-1,则表示您在元素可用于DOM之前发出该请求.或者您错误地标记了一个选择器并且它在@调用时不存在或者与.index()函数相关为空
归档时间: |
|
查看次数: |
38387 次 |
最近记录: |