投掷的方法jQuery的下降回调调用两次 [英] Jquery drop callback of droppable method called twice

查看:159
本文介绍了投掷的方法jQuery的下降回调调用两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下事件视图。查看ID为文件夹块。
     我的元素观是这样的:

I have a view with below event. View Id is "folders-block". my element is View are like this:

<ul>
  <li></li>
  <li></li>
  <li></li>
 </u>
 <ul>
     <li>
       <ul></ul>
     </li>
  </ul>

下面是骨干网的事件。

Below is the event in backbone.

  events{
   "mousedown .all-folders": "dragCustomFolders"
  },
  dragCustomFolders: function(e){
    $('#folders ul li').draggable({
      cursor: 'move',
      drag: this.dragElement,
      revert: "invalid"
    });

    $('#folders li').droppable({
      drop: this.cardDrop,
    });
  }

当我拖动里从一个UL到另一个UL降只调用一次。当我拖李元素相同ul元素下跌回调函数中的另一个li元素被称为两次。

When I drag an li from one ul to another ul drop is called only once. When I drag li element to another li element within same ul element drop callback function is called twice.

如何解决这个问题。

推荐答案

尝试设置 贪婪 选项为true可投掷的定义:

Try set greedy option to true on the droppable definition:

默认情况下,当一个元件被嵌套droppables下降,每
  投掷的将收到的元素。然而,通过设置这个选项
  真的,任何父母droppables将不会收到的元素。下降
  活动仍将正常的泡沫,但event.target可以检查
  看看哪些投掷的接受拖动元素。

By default, when an element is dropped on nested droppables, each droppable will receive the element. However, by setting this option to true, any parent droppables will not receive the element. The drop event will still bubble normally, but the event.target can be checked to see which droppable received the draggable element.

code:

$('#folders li').droppable({
    drop: this.cardDrop,
    greedy: true
});

这篇关于投掷的方法jQuery的下降回调调用两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆