¿Cómo coloreo una fila específica en una tabla según el valor en esa fila?
{{#each files}} <tr> <td style="text-align:left">{{filename}}</td> {{#if status === "Completed"}} <td style="text-align:right color:green">{{status}}</td> {{#else status === "Pending"}} <td style="text-align:right color:yellow">{{status}}</td> </tr> {{/each}}Recorro una lista de archivos y quiero colorear el estado dependiendo de si el valor está completo o está pendiente.
Primero, deberá crear un asistente de igualdad si aún no está usando uno:
Handlebars.registerHelper({ eq: (v1, v2) => v1 === v2, });Luego úsalo en el ciclo:
{{#each files}} <tr style="{{if (eq "Completed" status) "color:green"}} {{if (eq "Pending" status) "color:yellow"}}"> <td>{{filename}}</td> <td>{{status}}</td> </tr> {{/each}}