简体   繁体   English

可排序和可拖放的jQuery不断替换wordpress中的数据

[英]Sortable and Droppable Jquery keeps on replacing data in wordpress

I am trying to do a sort the data which is in a HTML form in to the div. 我正在尝试将HTML表单中的数据排序到div中。 Each time I drag new item, it will replace the previous item instead of sorting it from the top or the bottom. 每次我拖动新项目时,它都会替换上一个项目,而不是从顶部或底部进行排序。 I don't think there is anything to do with wordpress here. 我认为这里与wordpress没有任何关系。 Is just that I am developing it in wordpress. 只是我正在用wordpress开发它。 What have I done wrong or have I missed? 我做错了什么或错过了什么? Below are the code. 下面是代码。

script 脚本

$(function () {
    $("#blocks").droppable({
        drop: function (event, ui) {
            var id = ui.draggable.attr('id');
            layout = $.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText;
            $("#blocks").wrap( layout );

        }
    }).sortable({
        revert: true
    });
    $(".draggable").draggable({
         helper: "clone"
    });
});

html HTML

<div class="sortable" >
    <ul id="blocks" class="ui-sortable empty" ></ul>
</div>
<div id="slideout">
    <div id="slideMenu">
        <ul style="list-style-type: none;">
            <li id="template1" class="draggable">
                <img src="wp-content/themes/dynamictheme/img/template/template1.png"  width="200"/>
            </li>
            <li id="template2" class="draggable">
                <img src="wp-content/themes/dynamictheme/img/template/template2.png"  width="200"/>     
            </li>
        </ul>
    </div>
</div>

template html 模板html

<section class="success" id="template1" >
    <div class="container" style="width:auto;">
        <div class="row">
            <div class="col-lg-12 text-center">
                <h2>About</h2>
                <hr class="star-light">
            </div>
        </div>
        <div class="row">
            <div class="col-lg-4 col-lg-offset-2">
                <p>Freelancer is a free bootstrap theme created by Start Bootstrap. The download includes the complete source files including HTML, CSS, and JavaScript as well as optional LESS stylesheets for easy customization.</p>
            </div>
            <div class="col-lg-4">
                <p>Whether you're a student looking to showcase your work, a professional looking to attract clients, or a graphic artist looking to share your projects, this template is the perfect starting point!</p>
            </div>
            <div class="col-lg-8 col-lg-offset-2 text-center">
                <a href="#" class="btn btn-lg btn-outline">
                    <i class="fa fa-download">Download Theme</i> 
                </a>
            </div>
        </div>
    </div>
</section>

you are not dropping the data as a list item, append the layout variable inside a list element to the #blocks ul 您没有将数据作为列表项删除,而是将列表元素内的布局变量附加到#blocks ul

$("#blocks").droppable({
    drop: function (event, ui) {
        var id = ui.draggable.attr('id');
        layout = $.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText;
         $("#blocks").append('<li>' + layout + '</li>');

    }

Use two sortable lists instead of draggable and droppable then use this code: 使用两个可排序列表,而不是可拖动和可拖放列表,然后使用以下代码:

$(function() {
  $("#list2").sortable({
    connectWith:'.connect',
    stop: function (event, ui) {
      var id = ui.item.sortable.attr('id');
      ui.item.html($.ajax({type:"GET",url:'wp-content/themes/dynamictheme/templates/' + id + '.html',async:false}).responseText);
  }
   $("#blocks").sortable({
      connectWith:'.connect'
    });

 });

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

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