- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Breeze 数据属性中使用了多个验证器。下面是使用的 Breeze 模式:
{
"name": "property",
"dataType": "String",
"validators": [
{
"name": "required",
"context": {
//Data for Processing
}
},
{
"name": "maxLength",
"context": {
//Data for processing
}
}
]
}
在上述架构中,required 规则将首先执行,无论第一个验证器的结果如何,都会执行“maxLength”验证器。因此,即使该字段不是必需的,也会执行 maxLength 规则并捕获validationErrors。
有没有办法根据所需验证器的结果运行 maxLength 验证器?
提前致谢。
最佳答案
如果您希望在属性 A 具有特定值时使属性 B 成为必需,请不要使用标准必需验证器。写一个custom validator 。
下面是一个示例,其中将自定义验证器添加到 propertyB,使得仅当 propertyA 为 true 时才需要 propertyB。
这是可能的,因为 Breeze 传递给验证器函数的上下文参数包含一个“实体”属性,您可以访问该属性来检查 propertyA 的值。
propertyB.validators.push(
new breeze.Validator(
"myCustomValidator",
function(value, context) {
// when propertyA is false, skip validation.
if (!context.entity.propertyA)
return true;
// validate the value is a string.
if (typeof value !== 'string')
return false;
// validate the value is not an empty string.
return value !== null && value.length > 0;
},
{
messageTemplate: "'%displayName%' must be a string and is required when property A is true."
})
);
关于javascript - Breeze:如何根据另一个属性的值验证一个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27807141/
我正在考虑使用 Breeze js,并对其功能和随之而来的最佳实践有一些疑问。 服务器端元数据是否必须存在?如果我有一个非 EF WebApi Controller ,我是否仍然需要用 Provide
我们正在考虑使用breeze js来构建企业应用程序。 轻而易举的是,我们可以直接从客户端浏览器执行查询。这允许基于用户输入构造动态查询,而无需加载不必要的数据。我发现使用Breeze可以创建业务逻辑
我有一个从另一个表继承的表。当我运行该项目时,出现以下错误:无法获取未定义或空引用的属性“propertyref”...有什么想法吗? 最佳答案 编辑:从 v 1.3.1 Breeze 开始,现在支持
想知道是否有人知道扩展或配置 Breeze 以便服务器返回实体元数据中的附加信息的任何方法?我想使用这些附加数据来协助验证。 假设我有一个应用了一些数据注释的实体模型: public class Pe
我使用 Durandal/breeze 开发了一个 asp.net 解决方案。 这是我获取所有托运人的代码: var query = EntityQuery.from('Shippers')
我已经阅读了 Breeze 验证器信息,但不确定如何查看正在发生的实际错误。 错误:遇到客户端验证错误 - 有关更多详细信息,请参阅此对象上的实体错误集合。 我相信它在 entity.entityAs
我正在使用 Breeze 过滤客户端请求的数据。我的代码看起来有点像这样: 客户端 - 创建过滤谓词 var predicates = []; var criteriaPredicate = null
我在处理日期时遇到了一些问题。 我有一个带有日期字段的对象: public DateTime FechaInicio{get;设置; 此定义在数据库中生成以下字段: FechaInicio 日期时间不
我在处理日期时遇到了一些问题。 我有一个带有日期字段的对象: public DateTime FechaInicio{get;设置; 此定义在数据库中生成以下字段: FechaInicio 日期时间不
如果我使用微风加载部分实体: var query = EntityQuery.from('material') .select('Id, MaterialName, Mater
改进我关于如何使用获得的元数据在淘汰赛中创建验证规则的示例(http://stackoverflow.com/questions/13662446/knockout-validation-using-
我想更改 Breeze 的序列化程序,以便我的 javascript 对象是驼峰式的。在文档中它说这是可以做到的,但说这是有待解释的。 You can change the formatter's c
给定一个具有导航属性的实体,有没有办法判断空导航属性是否是因为子实体从未被加载,而不是集合已经加载但只是空的? 例如:我加载一个包含实体 A 列表的页面。每个实体 A 都有一个导航属性,它是实体 B
我使用 Entity Framework Code First + Durandal + Breeze 开发一个项目。 我有这些实体模型: public class Packing { [Ke
我正在尝试使用 breeze.js 保存一些实体。 Breeze 工作正常,它会根据需要保存所有更改。但是,我无法验证并确保授权是服务器端的。从我目前收集到的信息来看,我猜想做到这一点的唯一方法是检查
我们有一个轻而易举的客户解决方案,其中向父实体显示其子列表。我们对某些子实体进行硬删除。现在,当用户是执行删除操作的用户时,没有问题,但是当其他用户执行操作时,似乎没有办法使已经加载到缓存中的子项失效
我想用 Breeze.js 搜索文本 var qu = new breeze.EntityQuery("Projects") .where("Name", "s
从表面上看,这可能听起来像一个愚蠢的问题,但为什么 Hot Towel SPA Template包括 Breeze根本? 最近几天我一直在学习 Hot Towel 及其依赖项,据我所知,模板中没有任何
假设我想使用 Breeze 创建一个任务实体(我正在使用 EF),但是因为这是一个真实任务应用程序,所以该任务必须关联到当前登录的用户.任务具有需要在保存期间填充的 UserId 外键,这就是我遇到的
我正在尝试根据子实体的集合来过滤实体。这是我的实体(EF POCO): public class Customer { public int Id { get; set; } publ
我是一名优秀的程序员,十分优秀!