Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Laravel ajax usa una condición if dentro de un apéndice

Estoy tratando de generar una condición if en mis dos columnas en mi laravel ajax:

 $.each(response.all_categories, function (key, item) { $('tbody').append('<tr>\ <td><p class="font-weight-bold mb-0">'+item.category_name+'</p>'+item.category_description+'</td>\ <td>View:\ if ('+item.config_view_type+' == 'P'){\ <mark class="mark-orange">Public</mark>\ } elseif ('+item.config_view_type+' == 'R'){\ <mark class="mark-orange">Restricted</mark>}\ <br>Edit:\ </td>\ <td>View:\ </td>\ <td>\ <button type="button" value="'+item.category_id+'" class="btn btn-outline-secondary">\ <i class="fas fa-edit"></i> Edit</button><button type="button" value="'+item.category_id+'" class="btn btn-outline-secondary">\ <i class="fas fa-trash"></i> Delete</button>\ </td>\ </tr>'); });

my if condition about no muestra las columnas de mi tabla (sin salida). Descargo de responsabilidad: la tabla ya está conectada, las columnas se muestran sin problemas si elimino la condición if.

También probé:

 <td>View:\ @if ('+item.config_view_type+' == 'P')\ <mark class="mark-orange">Public</mark>\ @elseif ('+item.config_edit_type+' == 'R')\ <mark class="mark-orange">Restricted</mark>\ @endif\ <br>Edit:\ </td>\

¿Cuál es la sintaxis correcta para esto? Gracias por cualquier ayuda

Controlador:

 public function fetchcategory(){ $all_categories = HmsBbrCategory::all(); return response()->json([ 'all_categories'=>$all_categories, ]); }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar acento grave (`) en lugar de comillas

 $.each(response.all_categories, function (key, item) { $('tbody').append(` <tr> <td><p class="font-weight-bold mb-0">${item.category_name}</p>${item.category_description}</td> <td>View: <mark class="mark-orange">${getmark(item.config_view_type)}</mark> <br>Edit: </td> <td>View: </td> <td> <button type="button" value="${item.category_id}" class="btn btn-outline-secondary"> <i class="fas fa-edit"></i> Edit</button><button type="button" value="${item.category_id}" class="btn btn-outline-secondary"> <i class="fas fa-trash"></i> Delete</button> </td> </tr>`); }); function getmark(type) { var mark = ''; if (type == 'P'){ mark = 'Public' } else if (type == 'R'){ mark = 'Restricted' } return mark; }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!