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

发布于 2024-11-06 12:15:56 字数 2031 浏览 3 评论 0原文

我在这里为《魔兽世界》玩家提供了一个食谱跟踪工具:http://www.wowgeeks。 com/tracker.php?item=recipes。我有三个定制设计的列表:“有”列表、“需要”列表和可供选择的原始项目列表。我将最后一个列表作为可拖动的,并将其 connectToSortable 设置为前两个列表共享的类。

三个列表的 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>

这是可拖动/可排序的 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
});

由于某种原因,在我将一个项目从第三个列表拖到第一个列表一两次后,它突然拒绝配合。第三个列表中的项目突然变得不可拖动。但是将项目从第三个列表拖动到第二个列表效果很好。您可以尝试上面的链接并亲自测试一下。有人能告诉我可能是什么问题吗?

I have a recipe tracker tool for World of Warcraft players here: 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.

HTML for the three lists:

<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:

$(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光与爱终年不遇 2024-11-13 12:15:56
$('#add-list .tracker-item').draggable({
    connectToSortable   : '.target-list',

您仅将第三个列表连接到此处的第二个列表。如果将目标列表类添加到第一个列表,则可以从第三个列表拖动到第一个列表。

$('#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文