为什么可排序不起作用? -CodeIgniter

时间:2019-12-30 18:38:07

标签: javascript php ajax codeigniter jquery-ui-sortable

可稳固位置无法正常工作。我试图通过可排序的方式来给我的包裹指定位置。在更改模板之前,我有一些代码可以正常工作。

以下是HTML代码:

public function handle($request, Closure $next)
{
    URL::defaults(['account' => request('account')]);
    return $next($request);
}

以下是代码Javascript和Ajax:

<ul class="list-group" id="basic-list-group">
                                        <?php foreach($packageAdjustment as $get) { ?>
                                        <li class="list-group-item" data-index="<?php echo $get->packageId; ?>" data-position ="<?php echo $get->packagePosition; ?>">
                                            <div class="media">
                                                <div class="media-body">
                                                    <h5 class="mt-0"><?php if($this->session->userdata('people_lang') == "ar"){if(!empty($get->packageNameAr)){echo $get->packageNameAr;}else{echo $get->packageNameEn; }}else{echo $get->packageNameEn;} ?></h5>
                                                </div>
                                            </div>
                                            <input name="position" value="<?php echo $get->packagePosition; ?>" type="hidden" />
                                        </li>
                                        <?php } ?>
                                    </ul>

在此项目模板中,还有其他Javascript代码位于相同的位置。由于冲突检测,我添加了这些javascript文件。

<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>

<script>

    function savedata() {
        var position = [];
        $('.updated').each(function(){
            position.push([$(this).attr('data-index'),$(this).attr('data-position')]);
            $(this).removeClass('updated');
        });
        $.ajax({
            url : '<?php echo base_url(); ?>package/updatePos',
            method: 'POST',
            dataType : 'text',
            data:{
                update : 1,
                position : position
            },
            success:function(response){
                // Success notification
                toastr.success(<?php echo $this->lang->line('general_success'); ?>);
            },
            error:function(response){
                // Solid danger
                toastr.error(<?php echo $this->lang->line('general_error_occured'); ?>);
            }
        });
    }

    $('#basic-list-group').sortable({
        update: function (event, ui) {
            $(this).children().each(function(index){
                if($(this).attr('data-position') != (index+1) ){
                    $(this).attr('data-position',(index+1)).addClass('updated');
                }
            });
            savedata();
        }
    });



</script>

这里是控制器:

控制器:

<!-- BEGIN: Vendor JS-->
    <script src="<?php echo base_url(); ?>assets/vendors/js/vendors.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/forms/select/select2.full.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/extensions/dragula.min.js"></script>
    <!-- BEGIN Vendor JS-->

    <!-- BEGIN: ToastTr-->
    <script src="<?php echo base_url(); ?>assets/vendors/js/extensions/toastr.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/extensions/toastr.min.js"></script>
    <!-- END: ToastTr -->

    <!-- BEGIN: Page Vendor JS-->
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/pdfmake.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/vfs_fonts.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/datatables.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/datatables.buttons.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/buttons.html5.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/buttons.print.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/buttons.bootstrap.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/vendors/js/tables/datatable/datatables.bootstrap4.min.js"></script>
    <!-- END: Page Vendor JS-->

    <!-- BEGIN: Theme JS-->
    <script src="<?php echo base_url(); ?>assets/js/core/app-menu.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/core/app.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/components.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/footer.min.js"></script>
    <!-- END: Theme JS-->

    <!-- BEGIN: Page JS-->
    <script src="<?php echo base_url(); ?>assets/ltr/js/scripts/datatables/datatable.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/pages/app-user.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/navs/navs.min.js"></script>
    <!-- END: Page JS-->

    <script src="<?php echo base_url(); ?>assets/js/scripts/modal/components-modal.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/forms/select/form-select2.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/extensions/drag-drop.min.js"></script>
    <script src="<?php echo base_url(); ?>assets/js/scripts/tooltip/tooltip.min.js"></script>

0 个答案:

没有答案