问题描述
ko.validation.group
和ko.validatedObservable
有什么区别?在某些情况下我应该使用另一种方法吗?
What is the difference in ko.validation.group
and ko.validatedObservable
? Are there particular situations when I should use one over the other?
推荐答案
ko.validation.group
只是为您提供了(计算的)模型中所有错误消息的可观察值.它仅收集有关模型直接属性的错误消息.
The ko.validation.group
just gives you an (computed) observable of all the error messages in a model. It only collects error messages of direct properties of the model.
另一方面,ko.validatedObservable
不仅收集错误消息,而且将模型包装在可观察的范围内,并添加isValid
属性,该属性指示是否存在任何错误消息(即,模型是完全错误的).有效的).否则,它们本质上是相同的.
The ko.validatedObservable
on the other hand not only collects the error messages, but also wraps the model in an observable and adds an isValid
property which indicates whether or not there are any error messages (i.e., the model was completely valid). Otherwise, they're essentially the same.
如果您只想收集错误消息,则ko.validation.group
应该绰绰有余.如果您需要一个可观察到的东西来跟踪模型是否有效,则ko.validatedObservable
会为您完成一些工作.
If you're only interested in collecting the error messages, the ko.validation.group
should be more than enough. If you need an observable that keeps track of whether or not the model is valid, the ko.validatedObservable
does some of the work for you.
这篇关于淘汰赛验证ko.validation.group与ko.validatedObservable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!