我正在实施一个拖放操作,您可以在其中将用户拖动到一个角色。我知道如何获取用户 ID 和目标角色 ID,但我不知道如何获取从中拖动用户的角色 ID!
<div id="role_1" class="role">
<h5>Administrator</h5>
<ul class="users">
<li id="user_1">Foo</li>
<li id="user_2">Bar</li>
</ul>
</div>
<div id="role_2" class="role">
<h5>Member</h5>
<ul class="users">
<li id="user_1337">Baz</li>
</ul>
</div>
<script type="text/javascript">
$(function() {
// Get roles and users lists
var $templates = $(".role"),
$users = $(".users");
// let the user items be draggable
$("li", $users).draggable({
revert: "invalid", // when not dropped, the item will revert back to its initial position
containment: "document",
helper: "clone",
cursor: "move"
});
// let the roles be droppable, accepting the user items
$templates.droppable({
accept: ".users > li",
activeClass: "ui-state-highlight",
drop: function(event, ui) {
var $uid = ui.draggable.attr("id"),
$targetRid = $(this).attr("id"),
$sourceRid = ???;
// snip
}
});
});
</script>
提前感谢您的帮助。