2017-10-19 35 views
0

我在laravel 5.5中工作,我實現了數據表和im與ajax一起使用,我工作的很好,但現在我需要在數據表中顯示和img,但不知道怎麼樣。我閱讀了渲染文檔,但仍然輸了。 表代碼:如何在我使用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(); 
}); 

回答

-2

我發現我的錯誤當我寫這個問題時。這段代碼應該適合你。

+2

如果您發現錯誤並且問題仍然有價值,您應該在答案部分發布解決方案的解釋。如果問題不再有價值,您應該刪除它。 –

相關問題