使用KnockoutJS-Validation,我需要传递给自定义绑定,无论字段是否通过验证。猜测我需要以某种方式使用allBindingsAccessor参数在字段级别挂钩到KnockoutJS-Validation observable但不确定如何。
ko.bindingHandlers.mycustombinding = {
update: function (element, valueAccessor, allBindingsAccessor) {
allBindings = allBindingsAccessor(),
validationObservable = allBindings.validationObservable;
if (!validationObservable) {
//do cool jQuery stuff to the element if it doesn't validate
}
}
};
答案 0 :(得分:1)
库将obserabler isValid添加到扩展的var observable = ko.observable("f").extend({ number: true });
console.log(observable.isValid());