0

非常に基本的なものが欠けていることは知っていますが、「ドロップ可能な」DIVを積み重ねた状況でjQueryを使用する場合(ネストされたボックスを考えてください)、一番上のDIVで要素のドロップを許可して受け入れるにはどうすればよいですか次に、ドラッグ/ドロップ イベントをキャンセルして、下の他の「ドロップ可能な」DIV にも送信されないようにしますか?

        $('#'+objectID+" .task-droppable").droppable({
        accept: function(d) { 
            if(d.hasClass("source-task")||d.hasClass("source-sequence")){ //sequences can contain both sequences and tasks
                return true;
            } //end if
        }, //end accept
        activeClass: "isDropDest",
        //hoverClass: "isDragging",

        //this is used for both drag/drop and item moves
        drop: function(event, ui) {
            var draggableId = ui.draggable.attr("id");
            var droppableId = $(this).attr("id");

            //var sender_id = ui.sender.attr('id');
            //var receiver_id = $(this).attr('id');
            //var item_id = ui.item.attr('id');
            //var above_id = ui.item.prev().attr('id');
            //var below_id = ui.item.next().attr('id');

            //check if this is a drag/drop or a move by looking for the object class
            if(!$('#'+draggableId).hasClass('object')) {
                $('#'+draggableId).css('top', '0px');
                $('#'+draggableId).css('left', '0px');
                createObject(draggableId, droppableId);
            } else {
                //handle the move - do nothing
            } //end if

            event.stopPropagation();
        } //end drop
    }); //end droppable

すみません、今日はコーヒーが足りません。

4

1 に答える 1

2

貪欲なオプションを使用する必要があるようです

デフォルトでは、ネストされたドロップ可能オブジェクトに要素がドロップされると、各ドロップ可能オブジェクトがその要素を受け取ります。ただし、このオプションを true に設定すると、親のドロップ可能オブジェクトは要素を受け取りません。

$( ".selector" ).droppable({ greedy: true });

実施例

于 2013-11-11T22:05:04.237 に答える