问题描述:

I have three connected sortable lists using JqueryUI: list1, list 2 and list 3. Particular items in List 1 have the class number. If these number items are dragged then they can only be dropped into list 2 BUT NOT into list 3. How do I find out which list I am about to drop it in?

$("#list1").sortable({

start: function(event, ui) {

beforeStop: function (event, ui) {

if ($(ui.item).hasClass("number")) {

//Check which list is targeted

//If List 3 then

//$(List 3).sortable('cancel');

//End If

}

}

}

});

网友答案:

You could check the item on the update event. From the jQuery documentation:

This event is triggered when the user stopped sorting and the DOM position has changed.

Something like this might work for you:

update: function (e, ui) {
    var target = ui.item;
    var parent = item.closest('ul');
    if (parent.hasClass('thirdList')) {
        // do stuff
    }
    else {
        // do stuff
        return false;
    }
}

From what I understand of your situation, I don't think it would be necessary to check for the class number, since you can allow sorting for only the items that have class number.

Edit:

If you don't want to be able to drag into list 3 at all, you can just not make it sortable from when the page loads and have the other lists sortable:

$(function () {
    $('#list1').sortable({
        items: '.number'
    });
    $('#list2').sortable();
});
相关阅读:
Top