Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 对未定义变量的依赖关系(拖动,拖放),我还需要HTML。简言之,应该可以只运行代码,看看发生了什么。但我不会坚持:你似乎对另一个答案很满意,因为你已经接受了。所以我要继续。。。 $(document).ready(function () { new_Javascript_Jquery - Fatal编程技术网

Javascript 对未定义变量的依赖关系(拖动,拖放),我还需要HTML。简言之,应该可以只运行代码,看看发生了什么。但我不会坚持:你似乎对另一个答案很满意,因为你已经接受了。所以我要继续。。。 $(document).ready(function () { new

Javascript 对未定义变量的依赖关系(拖动,拖放),我还需要HTML。简言之,应该可以只运行代码,看看发生了什么。但我不会坚持:你似乎对另一个答案很满意,因为你已经接受了。所以我要继续。。。 $(document).ready(function () { new,javascript,jquery,Javascript,Jquery,对未定义变量的依赖关系(拖动,拖放),我还需要HTML。简言之,应该可以只运行代码,看看发生了什么。但我不会坚持:你似乎对另一个答案很满意,因为你已经接受了。所以我要继续。。。 $(document).ready(function () { new Sortable(drag, { group: 'sortables', multiDrag: true, // Enable multi-drag selectedClass: 'select

对未定义变量的依赖关系(
拖动
拖放
),我还需要HTML。简言之,应该可以只运行代码,看看发生了什么。但我不会坚持:你似乎对另一个答案很满意,因为你已经接受了。所以我要继续。。。
$(document).ready(function () {
    new Sortable(drag, {
        group: 'sortables',
        multiDrag: true, // Enable multi-drag
        selectedClass: 'selected', // The class applied to the selected items
        fallbackTolerance: 3, // So that we can select items on mobile
        animation: 150,
        onUpdate: function (e, tr) {
            addArray();
            checkFields();
        },
    });

    new Sortable(drop, {
        group: "sortables",
        multiDrag: true, // Enable multi-drag
        selectedClass: 'selected', // The class applied to the selected items
        fallbackTolerance: 3, // So that we can select items on mobile
        animation: 150,
        onChange: function (event, tr) {
            Sorting();
            addArray();
            checkFields();
        },
    });


    function addArray() {
        let uniqueArray = [],
            html = [];
        $('#drop').children().each(function () {
            const pk = $(this).data('pk');
            if (pk && !uniqueArray.includes(pk)) {
                uniqueArray.push(pk);
                html.push(`<option value="${pk}">${pk}</option>`);
            }
        });
        $('#id_articles').html(html.join(""))
    }


    function Sorting() {
        sort = [];
        $('#drop').children().each(function () {
            sort.push({ 'pk': $(this).data('pk'), 'order': $(this).index() })
        });
        let crf_token = $('[name="csrfmiddlewaretoken"]').attr('value') // csrf token
        $.ajax({
            url: "/rundown/sorts/",
            type: "post",
            headers: { "X-CSRFToken": crf_token },
            datatype: 'json',
            data: {
                'sort': JSON.stringify(sort),
            },
            success: function () {
                console.log('success')
            }
        });
    };

    function checkFields() {
        if ($('#drop tr').length >= 1) {
            $('#drop').find('#blank_row').remove();
        } else {
            $('#drop').append($("<tr>").attr("id", "blank_row")
                .append($('<td>').attr("colspan", '4')
                    .text('Drop here...')));
        }
    };
});

function stop_duplicate_in_array(array, value) {
  if (!value && value !== 0) return array; // value is falsy but not 0
  if (!array.includes(value)) array.push(value);
  return array;
}
function stop_duplicate_in_array(array, value) {
  if (value && !array.includes(value)) array.push(value);
  return array;
}