您可以像这样扩展淘汰赛验证核心:
var init = ko.bindingHandlers['validationCore'].init;
ko.bindingHandlers['validationCore'].init = function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
init(element, valueAccessor, allBindingsAccessor, viewModel, bindingContext);
var config = ko.validation.utils.getConfigOptions(element);
// if requested, add binding to decorate element
if (config.decorateInputElement && ko.validation.utils.isValidatable(valueAccessor())) {
var parent = $(element).parents(".form-group");
if (parent.length) {
ko.applyBindingsToNode(parent[0], { validationElement: valueAccessor() });
}
}
};
此代码使父表单组使用与输入相同的类进行装饰。