【发布时间】:2020-01-31 04:40:56
【问题描述】:
我有一个包含值的表。所以每一行都有重复的按钮。当用户按下复制按钮时,它会将值发送到 sweetalert2 弹出窗口。但是,它没有得到价值。我已经在 sweetalert 的文本中调用了{{item->description}},但它没有传递值?如何通过?我在重复按钮处传递了{{item->id}},但它不起作用。
html
<table class="table table-striped">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Description</th>
<th scope="col">Plan</th>
<th scope="col">From</th>
<th scope="col">To</th>
<th scope="col">Amount (RM)</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<?php $count = 1; ?>
@foreach ($packages as $item)
<tr>
<th scope="row">{{$count++}}</th>
<td>{{$item->description}}</td>
<td>{{$item->Plan->name}}</td>
<td>{{$item->from}}</td>
<td>{{$item->to}}</td>
<td>{{$item->price}}</td>
<td>
<a class="btn btn-xs btn-dark" href="/admin/insurance/product/package/edit/{{$product->id}}/{{$item->id}}">Edit</a>
<a class="deletePlanRecord btn btn-xs btn-danger" data-id="{{ $item->id }}"
id="delete" href="#">Delete</a>
<a class="duplicatePlanRecord btn btn-xs btn-danger" data-id="{{ $item->id }}"
id="delete1" href="#">Duplicate</a>
</td>
</tr>
@endforeach
</tbody>
</table>
javascript
$( ".duplicatePlanRecord" ).click(function(e) {
Swal.fire({
title: 'Are you sure to duplicate the plan?',
text: 'try {{$item->description}}',
input: 'text',
inputAttributes: {
autocapitalize: 'off'
},
showCancelButton: true,
confirmButtonText: 'Look up',
showLoaderOnConfirm: true,
preConfirm: (login) => {
return fetch(`//api.github.com/users/${login}`)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json()
})
.catch(error => {
Swal.showValidationMessage(
`Request failed: ${error}`
)
})
},
【问题讨论】:
-
你能在代码 sn-p 上做这个吗?
-
ID 必须是唯一的您在每一行上重复
id="delete"和id="delete1" -
@MisterJojo 但我根本不使用 id。我只使用 data-id 传递它。
-
此时
text: 'try {{$item->description}}',你不应该在this上引用被点击元素的data-id吗? -
在代码中留下错误是次要的?
标签: javascript php jquery html sweetalert2