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

查看:32
本文介绍了淘汰赛验证 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 不仅收集错误信息,还将模型包装在一个 observable 中,并添加一个 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 应该绰绰有余.如果您需要一个 observable 来跟踪模型是否有效,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天全站免登陆