jQuery:를 중지하는 방법을 도우미에서 제거되지 않으면 성공적으로 삭제
-
03-07-2019 - |
문제
나 draggable
사용자 지정 helper
.때로는 도우미 클론입니다 그리고 때때로 그것은 원래 요소입니다.
문제는 도우미가 원래 요소 지 떨어에 유효한 가능해졌 그것이 제거됩니다.나의 솔루션은 다음과 같이 지금까지:
나 on_dropped
콜백트 ui.helper.dropped_on_droppable
하기 true
;
에 stop
콜백의 드래그,내가를 확인하는 변수 그리고...나는 무엇을 할까?
$('.my_draggable').draggable({
stop : function(e, ui) {
if (!ui.helper.dropped_on_droppable) {
/* what do I do here? */
}
},
이 올바른 접근법?
해결책
Ok,I found 솔루션을 제공합니다!그것은 못생긴 그것은'규칙의 캡슐에 넣기,'하지만 적어도 그것은 작업을 수행합니다.
기억 이것은 그냥을 위한 특별한 경우!jQuery 처리할 수 있는 자신의 도우미 제거됩니다.내 경우가 도는 때로는 원래 요소이며 때로는 복제,그래서 그것은 항상 적절한 삭제 도우미 후 복귀.
element.draggable({
stop : function(e, ui) {
/* "dropped_on_droppable" is custom and set in my custom drop method
".moved_draggable" is custom and set in my custom drag method,
to differentiate between the two types of draggables
*/
if (!ui.helper.dropped_on_droppable & ui.helper.hasClass('moved_draggable')) {
/* this is the big hack that breaks encapsulation */
$.ui.ddmanager.current.cancelHelperRemoval = true;
}
},
경고:이 나누기 캡슐에 넣기 및되지 않을 수 있습 앞으로 호환성
다른 팁
나는 여기에 뭔가 빠졌을 수도 있지만 단순히 추가하는 경우가 아닙니다.
revert: "invalid"
Draggable이 클론이 아닌 원래 요소 인 경우 Draggable의 옵션에?
다중 선택 드래그 겔을 단일 DIV로 집계하는 사용자 정의 도우미를 사용합니다. 이것은 되돌리는 기능으로 인해 지배하지 않는 것 같습니다. 그래서이 체계를 생각해 냈습니다. 요소는 via .data ()를 추적하는 원래 부모에게 수동으로 추가됩니다.
.draggable({
helper: function() {
var div = $(document.createElement('div'))
.data('lastParent', $(this).parent());
return div;
},
start: function() {
//... add multiple selection items to the helper..
},
stop: function(event,ui) {
$( $(ui.helper).data('lastParent') ).append( $(ui.helper).children() );
}
}
이 접근법은 예쁜 애니메이션에서 잃어 버리지만이 문제를 가진 다른 사람에게 유용 할 수 있습니다.
제휴하지 않습니다 StackOverflow