拖曳下拉列表项目位置 [英] Drag & Drop list item position
问题描述
我正在尝试为客户创建案例优先级列表,并且将Jquery UI
用于拖放功能.
I'm attempting to create a case priority list for a client, and will be using Jquery UI
for the drag and drop feature.
此刻我遇到的问题是,一旦移动了list item
的新Index
,就会发现它.我希望你们中的一个人以前曾经遇到过这个问题,或者知道我怎么能得到这个?我真的很难找到它.
The problem I am sitting with at the moment is finding out the new Index
of the list item
once it has been moved. I am hoping one of you has encountered this before or knows how I can get this? I am really struggling to find it.
我尝试了很多SO线程,这些线程说我应该使用.index()
,但是我似乎无法正常工作.请在此 FIDDLE
I have tried lots of SO thread which say I should use .index()
, but i cant seem to get it working. Please see my attempt in this FIDDLE
$(document).ready(function () {
var Items = $("#SortMe li");
$('#SortMe').sortable({
disabled: false,
axis: 'y',
forceHelperSize: true,
update: function () {
var Newpos = $("li").index();
alert("You moved item to position " + Newpos);
}
}).disableSelection();
});
一旦list item
被删除,我想知道它的新position / index
,以便稍后可以在SQL
中使用它.
Once the list item
has been dropped, I would like to know its new position / index
so I can use this in SQL
later on in the process.
非常感谢, 迈克
推荐答案
基本上,您做的还不错,只是您定位的是错误的元素.相反,您应该检查ui.item
中当前拖动的元素.
Basically you're doing alright, except you're targeting the wrong element. You should instead check ui.item
for the current dragged element.
演示: http://jsfiddle.net/fKvv3/17/
这篇关于拖曳下拉列表项目位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!