简体   繁体   English

在JQuery UI中,当项目在可放置区域之间拖动时,如何减少计数?

[英]In JQuery UI, how can I decrement the count as items are dragged between droppable areas?

I'm using JQuery UI 1.8.3, please see diagram below for my page setup. 我正在使用JQuery UI 1.8.3,请参见下图以了解我的页面设置。
I am counting the number of items dragged into droppable areas however the count is not correct when I drag an item out from A to B. For example, if I drag item 1 to box A the count (#) for box A becomes 1, but then if I drag item 1 from A to B, the count for box A remains 1 but I need it to decrement to 0. 我正在计算拖动到可放置区域的项目数,但是当我将项目从A拖到B时,该计数是不正确的。例如,如果我将项目1拖到框A,则框A的计数(#)变为1,但是如果我将项目1从A拖到B,则框A的计数仍为1,但我需要将其递减为0。

  +------------------------+      +-----------------------+
  | Items (Dragable items) |      | A (Droppable Area)  # |
  |------------------------|      |-----------------------|
  |  item 1                |      |                       |
  |  item 2                |      |                       |
  |  item ...              |      +-----------------------+
  |  item n                |
  |                        |      +-----------------------+
  |                        |      | B (Droppable Area)  # |
  |                        |      |-----------------------|
  |                        |      |                       |
  |                        |      |                       |
  +------------------------+      +-----------------------+

My code looks like this to drop items: 我的代码如下所示删除项目:

$(".dropArea").droppable({
    ...
    drop: function(event, ui) {
    $(this).append($(ui.draggable));

    // count the items in the box and update
    ...
}

What would be the correct way to decrement the box count when an item is dropped out of the box A or B? 从A盒或B盒中取出物品时,减少盒数的正确方法是什么? Please let me know if anything doesn't make sense. 请让我知道是否没有任何意义。

Thanks. 谢谢。

On each drop event, count the number of objects in each droppable area and update your counters. 在每个放置事件中,计算每个可放置区域中的对象数并更新计数器。

Something like this would give you the count of objects: 这样的事情会给你对象的数量:

$(".dropArea").each(function (index, elem) {
    $(item).find(".count").text($(this).find("div").size());
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM