如何从控制器访问ngRepeat
循环内的给定记录,最终进行表单验证?从ngRepeat访问元素
我有以下的形成可动态添加的记录/用户删除:
<table class="table table-condensed span12" id="tableParticipants">
<!-- snip -->
<tbody>
<tr ng-repeat="person in people">
<td><input type="text" pattern="[0-9]*" data-provide="typeahead" placeholder="8675309" ng-model="person.empid"></td>
<td><input type="text" data-provide="typeahead" placeholder="Firstname Lastname" ng-model="person.name"></td>
<td><input type="text" placeholder="Title" ng-model="person.title"></td>
<td style="text-align: center"><i class="icon-remove" ng-click="removeParticipant()"></i></td>
</tr>
</tbody>
</table>
在提交我需要确保该雇员的ID是有效的形式,否则我会得到一个数据库错误。所以,当我通过循环工作时:
$scope.people.forEach(function(element, index, array)
{
if ($element['empid'] == BAD)
{
// set corredponding ngRepeat row to error
}
}
如何访问特定记录的给定行?
为什么你需要这样做?您可以用错误消息填充您的人员数组,然后只需用户界面显示它是否存在... – lucuma 2013-04-30 22:10:48