// Model
function User(item) {
var self = this;
this.id = ko.observable(item.id);
this.name = ko.observable(item.name);
this.surname = ko.observable(item.surname);
this.email = ko.observable(item.email);
// item.enabled is a boolean value.
this.enabled = ko.observable(item.enabled);
this.credit = ko.observable(new Credit(item.credit));
this.roles = ko.observableArray(item.roles);
}
<div data-bind='foreach: users'>
<!-- This below prints 1 -->
<span class='badge ' data-bind='text: enabled' ></span>
<!-- Both of those below don't activate (if check fails) -->
<span class='badge badge-success' data-bind='if: enabled==1'>OK</span>
<span class='badge ' data-bind='if: enabled==0' >NO</span>
</div>
我试过了:
<span class='badge badge-success' data-bind='if: enabled==1'>OK</span>
<span class='badge badge-success' data-bind='if: enabled'>OK</span>
<span class='badge badge-success' data-bind='if: enabled()'>OK</span>
<span class='badge badge-success' data-bind='if: enabled=="1"'>OK</span>
没有运气。我究竟做错了什么?