我正在玩一点拖累和放放弃ui,我对 DROP 感到有点难过。
您可以 see the Fiddle here 。
立即目标:
我只需要了解如何将.draggable
范围转换为.droppable
div中的任何一个
假设我在append()
的正确路径上,如何访问克隆的内容?
终极目标:
最后,我需要添加一种方法来删除drop-zone div中的项目,并将.textfield
input / div限制为只接受一个drop(.textarea
input / div可以接受无限制“有效载荷”的数量。)
CODE:
/* 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="&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));
}
});
欢迎提供任何帮助和建议
答案 0 :(得分:3)
好吧......到了底部。
clone
似乎并没有像人们期望的那样运作。
您最终必须使用自定义函数将自己的克隆打包到对象中,然后在drop
中将其从对象中拉回来。
您可以在jsFiddle上 see the working example here 以下是最终工作的内容:
// 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()));
}
});