如何從控制器訪問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