ax.ko.UserProfileModel = function(data) {
this.display_name = data.display_name;
this.enabled = data.enabled;
this.first_name = data.first_name;
this.gender = data.gender;
this.sales_rep_code = data.sales_rep_code;
this.billable = data.billable;
}
//VM
ax.ko.UserProfilesVM = function(data) {
var self = this;
self.userProfile = ko.observableArray([]);
self.userProfiles = ko.observableArray([]);
self.isLoading = ko.observable(false);
self.viewCreateEdit = ko.observable('');
self.carouselSettings = ax.Carousel.defaults;
self.canEditAccount = ko.observable();
self.isBillable = ko.observable();
self.populateUserProfiles = function(data) {
self.userProfiles($.map(data,function(i) { return new
ax.ko.UserProfileModel(i); }));
};
self.populateUserProfile = function(data) {
self.userProfile(new ax.ko.UserProfileModel(data));
};
};
<? if ($perms['user_profiles|edit_billable']===FALSE) { ?>
<div class="field">
<label><?=l(273)?></label>
<div class="input">
<input type="checkbox" name="billable" value="1" data-bind="checked: userProfile().billable, disable:isBillable();">
</div>
</div>
</div>
<? } ?>
答案 0 :(得分:2)
试试这个,更像是你可以按照@Jason的建议为你的绑定添加禁用http://knockoutjs.com/documentation/disable-binding.html:
MyVM = function(condition){
that = this;
that.flag = ko.observable(true);
that.condition = ko.observable(condition);
}
ko.applyBindings(new MyVM(true));
&#13;
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<div>
<input type="checkbox" data-bind="checked: flag, disable: condition"/>
</div>
&#13;