Retrieving Validation Errors from Breeze Entity Collection Properties

*爱你&永不变心* 提交于 2019-12-11 22:21:01

问题


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

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