我有一个li
是拖放,当页面刷新时有效但当我在列表中使用AJAX添加li
时,droppable
事件没有附加到它。如何将live
可放置事件附加到li
。
这是我到目前为止所尝试过的,
$('.main-menu.workspaces li').droppable({
hoverClass: "ui-state-hover",
tolerance: "pointer",
accept: '.notification-item.subtask',
drop: function (event, ui) {
var workspace_id = $(event.target).data('workspace');
var task_id = $(ui.draggable[0]).data('taskid');
$.post('{{route('workspace.assign', $subdomain)}}', {
workspace: workspace_id,
task: task_id
}).done(function(data) {
});
}
});
答案 0 :(得分:0)
感谢@Rory McCrossan提出的建议,这就是我所做的并且有效。
(function($){
var options = {
hoverClass: "ui-state-hover",
tolerance: "pointer",
accept: '.notification-item.subtask',
drop: function (event, ui) {
var workspace_id = $(event.target).data('workspace');
var task_id = $(ui.draggable[0]).data('taskid');
var href = $('.notification-body.todotask').attr('data-assignlink');
$.post(href,{workspace: workspace_id, task: task_id})
.done(function(data){
//todo
});
}
}
$('.main-menu.workspaces li').droppable(options);
// Attaching li to DOM using AJAX
function attachLi(){
$.ajax({
url: 'store',
method: 'POST',
data: {
task: searchString,
},
success: function (response) {
//attaching li to DOM
$('.task').append(response.html);
//Reinitializing Droppable
$('.main-menu.workspaces li').droppable(options);
}
});
}
...
.
.
})(jQuery);