简体   繁体   English

jQuery拖放项目计数和Ajax发布更新

[英]Jquery Drag Drop Item Count and Ajax Post Update

JQuery UI using drag drop. jQuery UI使用拖放。 When I drag and drop items, I want the value "Act and DISPLAY cards (0)" to change to 0. 拖放项目时,我希望值“ Act and DISPLAY cards(0)”更改为0。

I also need Ajax code to update the data when the persistence is finished. 持久性完成后,我还需要Ajax代码来更新数据。

https://jsfiddle.net/qxwLa98z/ https://jsfiddle.net/qxwLa98z/

<div class="col-lg-12" id="maximum-drag">
<div class="title-box">
    <h5>ACTIVE DISPLAY CARDS (<span>0</span>)</h5>
    <div style="font-size: 14px;color: #6e6e6e;">It is a list of your display cards that are active on the server.</div>
</div>
<div class="flex-container" id="active-cards">

</div>
<div class="title-box">
    <h5>YOUR DISPLAY CARDS</h5>
    <div style="font-size: 14px;color: #6e6e6e;">List of display cards you can use.</div>
</div>
<div class="flex-container" id="deactive-cards">
    <div id="item-1"><img src="https://svgur.com/i/Cx3.svg" style="width: 90%"></div>
    <div id="item-2"><img src="https://svgur.com/i/D0_.svg" style="width: 90%"></div>
    <div id="item-3"><img src="https://svgur.com/i/D1R.svg" style="width: 90%"></div>
    <div id="item-4"><img src="https://svgur.com/i/CzY.svg" style="width: 90%"></div>
    <div id="item-5"><img src="https://svgur.com/i/D0m.svg" style="width: 90%"></div>
    <div id="item-6"><img src="https://svgur.com/i/D0n.svg" style="width: 90%"></div>
</div>

    $("#deactive-cards, #active-cards").disableSelection();
$("#deactive-cards").droppable({
    accept: "#active-cards > div",
});
$("#active-cards").droppable({
    accept: "#deactive-cards > div",
});

$("#deactive-cards, #active-cards").sortable({
    placeholder: "",
    connectWith: ".flex-container",
    containment: "#maximum-drag",
    revert: true,
    scroll: false,
    update: function(event, ui) {

    }
});

please find the attached fiddle for your answer 请找到所附的小提琴作为答案

https://jsfiddle.net/px4fnws8/22/ https://jsfiddle.net/px4fnws8/22/

You can use the sortable's receive event instead. 您可以改用sortable的receive事件。

$("#deactive-cards, #active-cards").sortable({
  placeholder: "",
  connectWith: ".flex-container",
  containment: "#maximum-drag",
  revert: true,
  scroll: false,
  receive: function(event, ui) {
    $("#active-cards-count").text($("#active-cards").find("div").length);
  }
});

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

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