0
일부 코드를 사용하고 있는데 draggable 함수를 적용한 목록과 drop 함수가있는 다른 div가 있습니다.목록에서 목록 항목을 삭제 한 후 삭제합니다.
내가 달성하고자하는 것은 목록 요소가 삭제 될 때 상위 목록에서 제거되어 다른 목록에 추가 된 경우입니다.
<div id='dAvail'>
<ul>
<li><div class='abox'>1</div></li>
<li><div class='abox'>2</div></li>
</ul>
</div>
<div id='somewhereToDrop'>
</div>
<div id='newListHere'>
<ul>
</ul>
</div>
JS : 사람이 목록에서 해당 개체를 제거하는 방법을 알아 지적 할 수 있다면
$(document).ready(function(){
//add the droppable function to the divs in main list
$('#dAvail ul).each(function(){
$('li>div).draggable();
});
$('#somewhereToDrop').droppable({
tolerance:'touch',
drop:function(event,ui){
//this is where I am having problems.
//if I do ui.draggable I get an object representing the object I dragged but not 100% how to remove said object from the orginal list to then append to the new one.
//this is what i tried.
var t = ui.draggable[0]; //represents the div that i dropped.
$(t).parent().parent().remove($(t).parent());
//that is as far as I have gotten as this returns an error
});
하는 것이 좋을 것 여기
내가 함께 연주 된 코드입니다. 나는 심지어 $ (t) .parent(). eq()를 할 수 있는지 보려고했으나 작동하지 않았다. 아이디어는 목록 색인을 가져 와서 그런 식으로 제거하는 것이었다.감사
감사합니다. 나는 실제로는 제거를 전혀 부르지 않고 새로운 목록에 덧붙이기를 원한다는 것을 알았지 만, 그곳에 도착하는 방법을 찾는데 도움이되었습니다. – Vade
완전히 제거하지 않으려면 대신 .detach()를 사용하십시오. 그것은 객체를 반환하고 메모리에 보관하지만 DOM에서 제거합니다. 이렇게하면 나중에 다시 삽입 할 수 있습니다. –