3
我試圖用sorteable用戶連接到列表和我有被編碼爲一種形式:JQuery的排序不張貼正確的表單數據
<form action={{ secure_url('send-data') }} method="POST" data-parsley-validate class="form-horizontal form-label-left">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<input type="submit" name="Salvar">
<div class="col-md-6 col-sm-6 col-xs-6">Confirmados
<ul class="list-group list-group-sortable-connected connectedSortable" id="confirmados">@if(empty($confirmados)) <br /> @endif
@foreach ($users as $v)
@if (in_array($v->id, $confirmados))
<li class="list-group-item list-group-item-success"><input type="hidden" name="confirmados[]" value="{{$v->id}}">{{$v->nome}}</li>
@endif
@endforeach
</ul>
</div>
<div class="col-md-6 col-sm-6 col-xs-6">Ausentes
<ul class="list-group list-group-sortable-connected connectedSortable" id="ausentes">@if(empty($ausentes)) <br /> @endif
@foreach ($users as $v)
@if (in_array($v->id, $ausentes))
<li class="list-group-item list-group-item-danger"><input type="hidden" name="ausentes[]" value="{{$v->id}}">{{$v->nome}}</li>
@endif
@endforeach
</ul>
</div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">Pendentes
<ul class="list-group list-group-sortable-connected connectedSortable" id="pendentes">
@foreach ($users as $v)
@if (!in_array($v->id, $ausentes) && !in_array($v->id, $confirmados))
<li class="list-group-item list-group-item-info"><input type="hidden" name="pendentes[]" value="{{$v->id}}">{{$v->nome}}</li>
@endif
@endforeach
</ul>
</div>
</div>
</div>
</form>
而我的JS是這樣的:
<script type="text/javascript">
$(function() {
$("#ausentes, #confirmados, #pendentes").sortable({
connectWith: ".connectedSortable",
receive: function(event, ui) {
if (ui.sender[0].id === 'pendentes') {
ui.item.removeClass("list-group-item-info");
} else if (ui.sender[0].id === 'confirmados') {
ui.item.removeClass("list-group-item-success");
} else if (ui.sender[0].id === 'ausentes') {
ui.item.removeClass("list-group-item-danger");
}
if (this.id === 'pendentes') {
ui.item.addClass("list-group-item-info");
ui.item.attr("name", "pendentes[]");
} else if (this.id === 'confirmados') {
ui.item.addClass("list-group-item-success");
ui.item.attr("name", "confirmados[]");
} else if (this.id === 'ausentes') {
ui.item.addClass("list-group-item-danger");
ui.item.attr("name", "ausentes[]");
}
toastr.options.preventDuplicates = true;
$.ajax({
url: $('.form-horizontal').attr('action'),
data: $('.form-horizontal').serialize(),
method: $('.form-horizontal').attr('method'),
success:function(data) {
$('#ajax').html(data);
toastr.success("Alterações salvas com sucesso");
}
});
},
}).disableSelection();
});
</script>
但是,當我拖放列表中的用戶後,當ajax執行該帖子時,它會繼續發送數據作爲其原始內容。它沒有得到修改。
如果所有用戶都在「pendentes」列表中,即使我更改爲「confirmados」列表,它也會將所有用戶都發送爲「pendentes」。
那是什麼我做了更改後得到:
array:2 [▼
"_token" => "ynDyoSBCQ92jG5r5MKdItiuwq386GKaPU52rg2wv"
"pendentes" => array:11 [▼
0 => "20500"
1 => "24261"
2 => "24908"
3 => "24666"
4 => "24667"
5 => "24263"
6 => "24264"
7 => "24265"
8 => "24266"
9 => "24267"
10 => "24268"
]
]