淘汰赛验证ko.validation.group与ko.validatedObservable [英] Knockout Validation ko.validation.group vs ko.validatedObservable

查看:94
本文介绍了淘汰赛验证ko.validation.group与ko.validatedObservable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ko.validation.groupko.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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆