gpt4 book ai didi

jquery - 拖放克隆

转载 作者:行者123 更新时间:2023-12-01 05:04:36 25 4
gpt4 key购买 nike

我正在使用 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"
});
}
});

});

最佳答案

您似乎颠倒了回调函数接收的两个参数。

receive: function (ui, event) { 

}

应该是

receive: function (event, ui) { 

}

根据jQuery UI Docs :

All callbacks receive two arguments: The original browser event and a prepared ui object[...]

关于jquery - 拖放克隆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6918856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com