jQuery droppable添加现场活动



i有一个 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) {
    });
  }
});

感谢@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);

相关内容

  • 没有找到相关文章

最新更新