我有一个淘汰复选框,当它被检查时,它被发布为false。任何帮助,将不胜感激 视图:
<div class="managers" data-bind="foreach: managers">
<div class="row">
<div class="col-sm-12">
<div class="checkbox col-xs-12" data-bind="visible: isVerified == false && postalMessage != '' && postalMessage != null">
<label>
<input type="checkbox" data-bind="attr: { checked: isCorrect, name: 'Personnels[' + $index() + '].IsCorrect' }"> <b>@AddressResource.IsCorrect</b>
</label>
</div>
</div>
</div> <!-- .row -->
使用Javascript:
function Personnel(personnelId, firstName, middleName, lastName, primaryPhone, primaryPhoneExtension, secondaryPhone, secondaryPhoneExtension, fax, faxExtension, primaryEmail, secondaryEmail, postalAddress, city, state, zip, isVerified, isCorrect, postalMessage) {
var self = this;
self.personnelId = personnelId;
self.firstName = firstName;
self.middleName = middleName;
self.lastName = lastName;
self.primaryPhone = primaryPhone;
self.primaryPhoneExtension = primaryPhoneExtension;
self.secondaryPhone = secondaryPhone;
self.secondaryPhoneExtension = secondaryPhoneExtension;
self.fax = fax;
self.faxExtension = faxExtension;
self.primaryEmail = primaryEmail;
self.secondaryEmail = secondaryEmail;
self.postalAddress = postalAddress;
self.city = city;
self.state = state;
self.zip = zip;
self.isVerified = isVerified;
self.isCorrect = ko.observable(isCorrect);
self.postalMessage = postalMessage;
}
function KOViewModel() {
var self = this;
self.states = ko.observableArray();
var modelStates = mStates;
for (var i = 0; i < modelStates.length; i++) {
var state = modelStates[i];
self.states.push({
id: state.Value,
state: state.Text
});
}
self.managers = ko.observableArray();
var modelManagers = mManagers;
if (modelManagers.length === 0) {
self.managers.push(new Personnel(0, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""));
} else {
for (var x = 0; x < modelManagers.length; x++) {
var personnel = modelManagers[x];
self.managers.push(new Personnel(personnel.PersonnelId, personnel.FirstName, personnel.MiddleName, personnel.LastName, personnel.PrimaryPhone, personnel.PrimaryPhoneExtension, personnel.SecondaryPhone, personnel.SecondaryPhoneExtension, personnel.Fax, personnel.FaxExtension, personnel.PrimaryEmail, personnel.SecondaryEmail, personnel.PostalAddress, personnel.City, personnel.State, personnel.Zip5, personnel.IsVerified, personnel.IsCorrect, personnel.PostalMessage));
}
}
self.addPersonnel = function () {
self.managers.push(new Personnel(0, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""));
};
}
答案 0 :(得分:1)
您实际上并未使用敲除检查的绑定。您正在使用带有'checked'属性的attr绑定,该属性可能没有所有正确的事件挂钩。您只需将attr绑定参数之外的已检查部分移动到其自己的绑定。
data-bind="attr: { checked: isCorrect, ...
//becomes
data-bind="checked: isCorrect, attr: { ...