简体   繁体   English

jQuery UI可排序和可拖动列表交互无法正常工作

[英]jQuery UI Sortable and Draggable List Interaction Not Working Quite Right

I have a recipe tracker tool for World of Warcraft players here: http://www.wowgeeks.com/tracker.php?item=recipes . 我在这里有一个供魔兽世界玩家使用的食谱追踪器工具: http : //www.wowgeeks.com/tracker.php?item=recipes I have three custom-designed lists: a "Have" list, a "Need" list, and the list of original items to choose from. 我有三个自定义设计的列表:“有”列表,“需要”列表以及要选择的原始项目列表。 I have the last list as a draggable, with its connectToSortable set to a class that the first two lists share. 我将最后一个列表作为可拖动对象,并将其connectToSortable设置为前两个列表共享的类。

HTML for the three lists: 这三个列表的HTML:

<div class="sub-third">
    <h1>My Recipes</h1>
    <div class="tracker-list sortable" id="have-list">
    </div>
</div>
<div class="sub-third">
    <h1 style="color: #f90;">Recipes I Need</h1>
    <div class="tracker-list sortable" id="need-list">
    </div>
</div>
<div class="sub-third">
    <h1 style="color: #eee;">Add Recipes</h1>
    <div class="tracker-list" id="add-list">
        <div class="tracker-item" id="itemid_123">
            <a class="tracker-icon" rel="item=43509"><img class="wow-icon" src="/images/icons/small/inv_scroll_03.jpg" alt="Icon" /></a>
            <p>Bad Clams</p>
        </div>
        <!-- ETC... -->
    </div>
</div>

And here is the JavaScript for the draggable/sortables: 这是可拖动/可排序的JavaScript:

$(function() {
    $('#add-list .tracker-item').draggable({
        connectToSortable   : '.sortable',
        helper              : 'clone'
    });

    $('#have-list, #need-list').sortable({
        connectWith : '.tracker-list',
        cursor      : 'move',
        revert      : true,
        placeholder : 'ui-state-highlight',
        update      : function() {
            var order = $(this).sortable('serialize');
            order += '&userid=1&itemtype=Recipes&charid=0';
            //alert(order);
        }
    });

    $('.tracker-list, .tracker-item').disableSelection(); // So dragging doesn't accidentally select any text

    $('#have-list, #need-list').sortable('refresh'); // Refresh the lists
});

For some reason, after I drag an item from the 3rd list to the 1st list one or two times, it suddenly refuses to cooperate. 由于某种原因,当我将一个项目从第三列表拖到第一列表一两次后,它突然拒绝合作。 The items in the 3rd list suddenly become un-draggable. 第三列表中的项目突然变得无法拖动。 But dragging items from the 3rd to the 2nd list works just fine. 但是将项目从第三列表拖到第二列表就可以了。 You can try the link above and test it out for yourself. 您可以尝试上面的链接,然后自己进行测试。 Can anybody tell me what the problem might be? 谁能告诉我可能是什么问题?

$('#add-list .tracker-item').draggable({
    connectToSortable   : '.target-list',

You're connecting the third list only to the second list here. 您仅将第三个列表连接到此处的第二个列表。 If you make add the target-list class to the first list you can then drag from third to first. 如果您将target-list类添加到第一个列表,则可以从第三个列表拖动到第一个列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM