I want to use different prefix icon for admin and user in a table column but the following js doesn't work;
readUsers.data.user_type gives an array.
without knowing the structure of your data, I am taking a guess here:
readUsers.data.user_type[i]
or readUsers.data[i].user_type
Hello, you can try
currentRow.user_type === "Admin" ? "icon" : "icon"
An alternative:
You can define tag by tag the icons in Add-ons > Option list
you say:
readUsers.data.user_type gives an array.
but the code says readUsers.data.user_type
is a string.
If it is actually an array (I'd assume so that a user could have more than one 'type' or 'role') then you need to check all the items in the array. As your code stands right now you're comparing readUsers.data.user_type
with typeof Array
to "Admin" with typeof String
. The comparison will always be false, which is why the mapped array in your screenshot shows 3 icons for the false condition of the ternary operator.
I believe what you are looking for:
{{ readUsers.data.user_type.includes("Admin") ? admin_icon : user_icon }}
if this doesn't help, I'd suggest taking a look at @ScottR's answer and possibly using it with this one.
Second solution works for me. Thank You!