Reputation: 825
So with Knockout I can show text based on if a condition returns true or false like this:
data-bind="text: status==0 ? 'Sent' : 'Failed'"
However, I need to add another condition, so that if status==1
then it returns Pending
. I guess this probably just a general JS question vs Knockout.
Anyway, is it possible to do something like that? Thanks!
Upvotes: 0
Views: 55
Reputation: 1969
Sounds like you really want to use Knockout's Computed Observables. This will allow you to return different computed values based on your status.
function ViewModel() {
this.status = ko.observable();
this.statusText = ko.computed(function() {
if (this.status() == 0) {
return 'sent'
} else {
return 'failed';
}, this);
}
Upvotes: 2