【发布时间】:2018-06-08 23:54:03
【问题描述】:
我在 laravel 中遇到问题,无法确认 sweetalert
删除帖子<script>
!function ($) {
"use strict";
var SweetAlert = function () {
};
//examples
SweetAlert.prototype.init = function () {
$('.sa-remove').click(function () {
swal({
title: "are u sure?",
text: "lorem lorem lorem",
type: "error",
showCancelButton: true,
confirmButtonClass: 'btn-danger waves-effect waves-light',
confirmButtonText: "Delete",
cancelButtonText: "Cancel",
closeOnConfirm: true,
closeOnCancel: true
},
function(){
window.location.href = "{{ route('panel.posts.remove',$post->id) }}";
});
});
},
//init
$.SweetAlert = new SweetAlert, $.SweetAlert.Constructor = SweetAlert
}(window.jQuery),
//initializing
function ($) {
"use strict";
$.SweetAlert.init()
}(window.jQuery);
</script>
但是我在视图中有一个foreach,它只是通过了最后一个foreach 帖子id,当我想删除例如表中的第二个帖子时,最后一个删除了!
这是桌子:
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Body</th>
<th>Author</th>
<th>Operations</th>
</tr>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<td>{{ $post->id }}</td>
<td>{{ $post->title }}</td>
<td>{{ $post->body }}</td>
<td>{{ $post->user->name }}</td>
<td>
<a href="#" class="sa-remove"><button class="wave-effect btn btn-danger btn-bordred wave-light"><i class="fa fa-times"></i></button></a>
</td>
</tr>
@endforeach
</tbody>
我当然是新手!
【问题讨论】:
标签: javascript laravel parameter-passing laravel-blade sweetalert