拖放删除克隆
我正在将 jquery Draggables 与 Sortable 一起使用。我在左侧有一个元素列表,需要将其拖放到右侧的不同 div 中。可以将左侧相同的项目放入多个框中,因此我使用了助手:“克隆”。一切正常,直到我需要获取对接收事件中克隆的新元素的引用,以便我可以向其添加单击处理程序。
我需要新元素的引用!
<div>
<div style="float: left; width: 300px;">
<div id="FieldList">
<h2>Loading</h2>
</div>
<input type="button" name="cmdTest" id="cmdTest" value="Test" />
</div>
<div style="float: right; width: 300px;">
<div>
<div>Select Columns</div>
<div class="Toolbar"></div>
<div id="SelectFields" class="DroppableField">
</div>
</div>
<div>
<div>Conditions</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
<div>
<div>Order</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
</div>
<div style="clear: both;">
</div>
</div>
Javascript:
$(document).ready(function () {
$(".DroppableField").sortable({
revert: true,
receive: function (ui, event) {
// ui.helper always seems to be null. Many of the other properties seem to reference the original item. I need the NEW ONE!!!
$(ui.helper).dblclick(function () {
});
}
});
$.ajax({
url: "/condition/getconditions",
data: {},
dateType: "json",
type: "POST",
success: function (data, successcode, jqXHR) {
var html = "";
for (var i = 0; i < data.length; i++) {
$("#FieldList").append("<div>" + data[i].Description + "</div>").find("div:last").data("fielddata", data[i]);
//html += ;
}
$("#FieldList div").draggable({
connectToSortable: ".DroppableField",
helper: "clone",
revert: "invalid"
});
}
});
});
I'm using jquery Draggables with a Sortable. I have a list of elements on the left that I need to drag and drop into different divs on the right. It's possible to put the the same items from the left into multiple boxes, so I used helper: "clone." All works well until I need to get a reference to the new element that was cloned in the receive event so I can add a click handler to it.
I need a reference to the new element!
<div>
<div style="float: left; width: 300px;">
<div id="FieldList">
<h2>Loading</h2>
</div>
<input type="button" name="cmdTest" id="cmdTest" value="Test" />
</div>
<div style="float: right; width: 300px;">
<div>
<div>Select Columns</div>
<div class="Toolbar"></div>
<div id="SelectFields" class="DroppableField">
</div>
</div>
<div>
<div>Conditions</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
<div>
<div>Order</div>
<div class="Toolbar"></div>
<div class="DroppableField" style="background-color: Gray; height: 200px;">
</div>
</div>
</div>
<div style="clear: both;">
</div>
</div>
Javascript:
$(document).ready(function () {
$(".DroppableField").sortable({
revert: true,
receive: function (ui, event) {
// ui.helper always seems to be null. Many of the other properties seem to reference the original item. I need the NEW ONE!!!
$(ui.helper).dblclick(function () {
});
}
});
$.ajax({
url: "/condition/getconditions",
data: {},
dateType: "json",
type: "POST",
success: function (data, successcode, jqXHR) {
var html = "";
for (var i = 0; i < data.length; i++) {
$("#FieldList").append("<div>" + data[i].Description + "</div>").find("div:last").data("fielddata", data[i]);
//html += ;
}
$("#FieldList div").draggable({
connectToSortable: ".DroppableField",
helper: "clone",
revert: "invalid"
});
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎颠倒了回调函数接收的两个参数。
应该
根据 jQuery UI 文档:
You seem to have inverted the two parameters the callback functions receives.
Should be
According to the jQuery UI Docs: