【发布时间】:2017-10-19 19:52:47
【问题描述】:
我在 laravel 5.5 中工作,我实现了数据表并将它与 ajax 一起使用,我工作正常,但现在我需要在数据表中显示和 img,但不知道如何。我阅读了渲染文档,但我仍然迷路了。 表格代码:
<div class="row-fluid margin-body">
<table id="productos" class="table table-hover table-condensed" >
<thead>
<tr>
<th >Id</th>
<th>Producto</th>
<th>Cantidad </th>
<th>img</th>
<th></th>
</tr>
</thead>
</table>
</div>
Ajax 在表格中创建内容:
$(document).ready(function(){
listar();
});
var listar = function (){
var table = $('#productos').DataTable({
"processing": true,
"serverSide": true,
"ajax": "ajaxProducto",
"columns":[
{data:'id'},
{data:'nombre'},
{data:'stock'},
{data: 'imagen',
"render": function(data, type, row) {
return '<img src="'+data+'" />';
}},
{defaultContent:
"<a type='button' class='editar btn btn-xs btn-mini btn-primary' data-toggle='modal' data-target='#myModalEditar'>Editar</a><a type='button' class='eliminar btn btn-xs btn-mini btn-danger' >Eliminar</a><a type='button' class='btn btn-xs btn-mini btn-success detalles' data-toggle='modal' data-target='#myModalDetalles'>Detalles</a>"
}
],
"language": idioma_esp
});
}
这是我想展示我的img的地方
{data: 'imagen',
"render": function(data, type, row) {
return '<img src="img/productos/'+data+'" height="42" width="42"/>'; }}
我的路线:
Route::get('/ajaxProducto', function() {
return datatables()->collection(App\Producto::all())->toJson();
});
【问题讨论】: