Reputation: 1560
I have a field called is_admin. I am using VueJS to build a autocompleting search of all of the users.
I want to output the is_admin field as either true/false or yes/no, but my database field is boolean, 1 or 0.
How can I output the value in a readable way instead of as the boolean field?
Upvotes: 2
Views: 4565
Reputation: 12711
If you need to do this more than once, you might consider putting the logic in a filter:
Vue.filter('yesno', function (value) {
return value ? 'Yes' : 'No';
})
and then use it like this:
<div>
Admin? {{ is_admin | yesno }}
</div>
Upvotes: 12
Reputation: 25221
Try something like this:
<span>{{ user.is_admin ? "Admin" : "User" }}</span>
Upvotes: 10