I have a field called is_admin. I am using VueJS to build a autopleting 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?
I have a field called is_admin. I am using VueJS to build a autopleting 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?
Share Improve this question asked Feb 4, 2016 at 18:56 KinsDotNetKinsDotNet 1,5605 gold badges27 silver badges59 bronze badges2 Answers
Reset to default 12If 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>
Try something like this:
<span>{{ user.is_admin ? "Admin" : "User" }}</span>