从微风实体集合属性检索验证错误 [英] Retrieving Validation Errors from Breeze Entity Collection Properties
本文介绍了从微风实体集合属性检索验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以如果我有一个实体 Foo
与许多酒吧
和 Bazs
。有没有一种通用的方式来检索 Bars
和 Bazs
在 Foo上的验证错误
沿着 myFoo.getAllValidatioErrors()
解决方案
这里有一种方法可以实现:
//获取主实体的验证错误。
var validationErrors = entity.entityAspect.getValidationErrors()
// concat所有子实体验证错误...
.concat(
//抓取每个导航属性数组
entity.entityType.navigationProperties
.filter(function(propertyInfo){return!propertyInfo.isScalar;})
.map(function(propertyInfo){return entity [propertyInfo.name];})$
.reduce(function(a,b){return a.concat(b);})
// validate
.map(function(childEntity){return childEntity.getValidationErrors();})
//将ValidationError数组的数组变成一个大的验证错误数组
。 reduce(function(a,b){return a.concat(b);})
);
I have a Breeze entity that has several collections of other entities. When retrieving the validation errors for the first entity, I want to also retrieve the errors from each entity in its collections.
So that if I have an entity Foo
with many Bars
and Bazs
. Is there a generic way to retrieve the validation errors for the Bars
and Bazs
on a Foo
along the lines of myFoo.getAllValidatioErrors()
解决方案
here's one way you could do it:
// get primary entity's validation errors.
var validationErrors = entity.entityAspect.getValidationErrors()
// concat all child entity validation errors...
.concat(
// grab every navigation property array.
entity.entityType.navigationProperties
.filter(function (propertyInfo) { return !propertyInfo.isScalar; })
.map(function (propertyInfo) { return entity[propertyInfo.name]; })
// flatten the array of entity-arrays into one big array of entities.
.reduce(function (a, b) { return a.concat(b); })
// validate the entities.
.map(function (childEntity) { return childEntity.getValidationErrors(); })
// flatten the array of ValidationError-arrays into one big array of validation errors.
.reduce(function (a, b) { return a.concat(b); })
);
这篇关于从微风实体集合属性检索验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文