vendredi 27 octobre 2017

VueJS add class depending item v-for

I would like make a table stripped green or red (boostrap). Here is the context : I receive a list from an ajax call and here is the table row :

<tr v-for="item in items" class=getStyle(item)>
<td></td>
</tr>

My list of item is :

public class Wall
{
    public String Line{ get; set; }
    public BookRetrive Type { get; set; }
}

The value of Type is a Enum (Value == 0 / 1) when he is receive by the ajax call. So if the item.type == 0, i would like to add the class "table-success" otherwise is would like to add the class "table-error".

computed: {
            getStyle(item) {
                return item.type === 0 ? "table-success" : "table-error";
            }
        }

But i can't get it, could you help me please. Thank you

Aucun commentaire:

Enregistrer un commentaire