【发布时间】:2021-04-06 22:49:49
【问题描述】:
我有表 <thead> 在刀片中初始化,foreach 在控制器中循环 <tbody>
这就是它在控制器中的样子:
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->year.'</td>
<td>
<a href={{url(/edit/'.$row->id.')}} class="...">Edit</a>
<a href="#" class="...">Delete</a>
</td>
</tr>
';
}
在刀片中,初始化如下:
<table>
<thead>
<tr>
<th>Year</th>
<th> BUTTON </th>
</tr>
</thead>
<tbody></tbody>
</table>
和script 将数据提取到<tbody>:
<script>
$(document).ready(function(){
fetch_customer_data();
function fetch_customer_data(query = '')
{
$.ajax({
url:"{{ route('live_search.action') }}", // live_search: is the blade where the table is
method:'GET',
data:{query:query},
dataType:'json',
success:function(data)
{
$('tbody').html(data.table_data); // TABLE DATA
$('#total_records').text(data.total_data);
}
})
}
$(document).on('keyup', '#search', function(){
var query = $(this).val();
fetch_customer_data(query);
});
});
</script>
数据和按钮出现在表格中,但按钮无法正常工作。我如何使用表格中的按钮存在问题,此按钮:<a href= "{{url(/edit/'.$row->student_id.')}}" class="...">Edit</a> 生成此网址:http://sms.test/%7B%7Burl(/edit/2)%7D%7D 而网址应如下所示:http://sms.test/edit/ID22 但是当我将href= "{{url(/edit/'.$row->student_id.')}}" 更改为@ 987654333@ 它在 url 栏中显示#。所以我想问题出在这一行"{{url(/edit/'.$row->student_id.')}}"
这是到edit 的路径:
Route::get('/edit/{id}', 'StudentController@edit');
function edit @controller 看起来像这样:
public function edit($id)
{
$student = Student::find($id);
$students = Student::all();
return view('student',['students'=>$students,'student'=>$student,'layout'=>'edit']);
}
我尝试了所有我知道的方法,但无法让它发挥作用:(请帮助
【问题讨论】:
标签: php jquery laravel html-table