Knockout Validation ko.validation.group vs ko.validatedObservable

穿精又带淫゛_ 提交于 2019-11-29 11:57:08

问题


What is the difference in ko.validation.group and ko.validatedObservable? Are there particular situations when I should use one over the other?


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/13057018/knockout-validation-ko-validation-group-vs-ko-validatedobservable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!