2

我正在玩一些拖放用户界面,我对DROP有点难过。
你可以在这里看到小提琴

即时目标:
我只需要找出如何让.draggable跨度进入任何一个.droppablediv。
假设我走在正确的道路上append(),我该如何访问克隆的内容?

终极目标:
最终,我需要添加一种从放置区 div 中删除项目的方法,并将.textfieldinput/div 限制为仅接受一个 drop(.textareainput/div 可以接受无限数量的“有效负载”)。

代码:

/* html */
<table>
    <thead>    
        <tr role="row">
            <th class="sorting_asc" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" style="width: 494px;" aria-sort="ascending" aria-label="Company: activate to sort column descending">Company</th>
            <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 66px;" aria-label="Contact">Contact</th>
            <th class="sorting_disabled" role="columnheader" rowspan="1" colspan="1" style="width: 79px;" aria-label="&amp;nbsp;">&nbsp;</th>
        </tr>
    </thead>
    <tbody role="alert" aria-live="polite" aria-relevant="all">
        <tr class="odd">
            <td class="sorting_1 has_draggable_children">
                <span draggable="true" class="ui-draggable" data-companyid="0101" data-companyname="**BD">**BD</span>
            </td>
            <td><a href="#4621">Contacts</a></td>
            <td><a href="#4621">Edit</a>
                <a href="#4621">Delete</a>
            </td>
        </tr>
        <tr class="even">
            <td class="sorting_1 has_draggable_children">
                <span draggable="true" data-companyid="0202" data-companyname="0024" class="ui-draggable">0024</span>
            </td>
            <td><a href="#4438">Contacts</a></td>
            <td><a href="#4438">Edit</a>
                <a href="#4438">Delete</a>
            </td>
        </tr>
        <tr class="odd">
            <td class="sorting_1 has_draggable_children">
                <span draggable="true" class="ui-draggable" data-companyid="0303" data-companyname="Acme, Inc.">Acme Anvil Corp</span>
            </td>
            <td><a href="#4621">Contacts</a></td>
            <td><a href="#4621">Edit</a>
                <a href="#4621">Delete</a>
            </td>
        </tr>
   </tbody>
</table>

<section class="offset7" id="dragged-drop-zone" >
    <div class="look-like-input textfield droppable" contenteditable></div>
    <br />
    <div class="look-like-input textarea droppable" contenteditable></div>
</section>

.

/* js */
// DRAG
$('span[draggable]').draggable({
    revert: true,
    helper: "clone"
});

// DROP
$('.droppable').droppable({
    tolerance: 'pointer',
    drop: function(event, ui) {
        //console.log(this);
        $(this).append($(ui.helper));
    }
});

欢迎任何和所有的帮助和建议

4

1 回答 1

3

好吧……深究了。

clone只是似乎并不像人们期望的那样运作。
您最终不得不使用自定义函数将您自己的克隆打包到一个对象中,然后将其从drop.

您可以在 jsFiddle 上查看工作示例。
这是最终的工作:

// Drag
$('span[draggable]').draggable({
    revert: true,
    helper: function() {
        var container = $('<div/>');
        var dragged = $(this);
        container.append(dragged.clone());
        return container;
    }
});

// Drop
$('.droppable').droppable({
    tolerance: 'pointer',
    drop: function(event, ui) {
        $(this).append($(ui.helper.children()));
    }
});
于 2013-01-14T22:31:04.867 回答