2017-10-19 6 views
0

Im laravel 5.5에서 작업하고 있으며 데이터 테이블을 구현하고 메신저를 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> 

아약스 테이블에있는 콘텐츠를 만들 수는 : 내 IMG 보여주고 싶은 곳

$(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 

       }); 


} 

이다

{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

오류가 발견되어 여전히 질문이있는 경우 답변 섹션에 해결책에 대한 설명을 게시해야합니다. 질문에 더 이상 가치가 없으면 제거해야합니다. –