使用此代码(简化):
<table>
<thead>
<!-- Column headings -->
<tr>
<th repeat.for="column of columns">
${column.display}
</th>
</tr>
</thead>
<tbody>
<!-- Display all records -->
<tr repeat.for="record of records">
<!-- Show all column data for each record -->
<td repeat.for="column of columns">
<input type="text" value.bind="record[column.bind] & validate">
</td>
</tr>
</tbody>
</table>
我创建了一组这样的规则:
this.rules = ValidationRules
.ensure("gs_mark").required().minLength(1).maxLength(3)
.ensure("gs_min").required().minLength(1).maxLength(3)
.ensure("gs_max").required().minLength(1).maxLength(3)
.ensure("gs_description").required().minLength(2).maxLength(20)
.rules;
现在我需要将这些规则应用于记录,以便我可以验证所有输入框。
我该怎么做?我应该.map()
记录并在每个记录上this.validationCtrl.addObject(this.record, this.rules);
吗?我可以以某种方式设置每种控件类型的绑定验证,而无需将其应用于每个记录吗?我是以错误的方式接近这个吗?