1

我正在使用 YUI3,我一直在尝试<tr>在表格中制作可拖动的标签,但没有运气。我发现我可以拖动<div>节点,但由于某种原因我不能拖动<tr>. 这不应该是一个限制,我找到了 YUI2 的示例,但代码与 YUI3 完全不同,我无法弄清楚。

有谁知道你是否可以<tr>在 YUI3 中拖动节点,以及如何做到这一点?

这是我的代码:

YUI({combine: true, timeout: 10000}).use("dd-drop", "dd-constrain", "node", function (Y) {
    var drags = Y.Node.all('#draftable-players tr.drag');
    drags.each(function(v, k) {
        var dd = new Y.DD.Drag({
            node: v,
            dragMode: 'intersect'
        }).plug(Y.Plugin.DDConstrained, {
            constrain2node: '#draft'
       });
       dd.on('drag:end', function(e) {
           e.preventDefault();
       });
    });
});

以及相关的 HTML:

<div id="draft">

<table id="draftable-players">
<tr class="drag"><td>some stuff</td></tr>
<tr class="drag"><td>some more stuff</td></tr>
</table>

<table> another table, i'm trying to drag <tr>s from the other one to this one
</table>

</div>

任何帮助,将不胜感激。谢谢!

4

1 回答 1

1

This question didn't garner too much interest, but I thought I'd answer it just as well in case someone comes across this in the future.

I found that you can't drag <tr> elements between two tables, only within the same table - further inspection of the YUI2 examples I mentioned above were doing exactly this, dragging within a given table.

I've since converted my tables to <div> elements and styled them to look like a <table> using CSS, and now I can drag from one 'table' to another. If anyone is curious to see some code for dragging and dropping, check out YUI3's docs here.

于 2009-11-30T10:59:36.377 回答