问题
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()
回答1:
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); })
);
来源:https://stackoverflow.com/questions/26661455/retrieving-validation-errors-from-breeze-entity-collection-properties