我是AngularJS的学习者,我试图更新我的表列表用户,使其能够编辑用户信息,并能编辑下面的代码使用的表列表对象,但是在保存编辑用户信息时出现异常。
<?php $numrows = count( get_sub_field( 'agence_post' ) );
echo $numrows;?>
<div ng-repeat="employee in employeeList | filter:{name:searchName}">
<div class="panel panel-primary" ng-class="{'panel-success':employee.id==selectedId}">
<div class="panel-heading">
<h3 class="panel-title">{{employee.name}}</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<div class="row" class="vertical-align">
<div class="col-xs-2">
<img ng-src="{{employee.photoPath}}">
</div>
<div class="col-xs-10">
<div class="row">
<div class="col-xs-2">
Gender
</div>
<div class="col-xs-10">
{{employee.gender}}
</div>
</div>
<div class="row">
<div class="col-xs-2">
DateOfBirth
</div>
<div class="col-xs-10">
{{employee.dateOfBirth | date}}
</div>
</div>
<div class="row">
<div class="col-xs-2">
PhoneNumber
</div>
<div class="col-xs-10">
{{employee.phoneNumber}}
</div>
</div>
<div class="row">
<div class="col-xs-2">
ContactPreference
</div>
<div class="col-xs-10">
{{employee.contactPreference}}
</div>
</div>
<div class="row">
<div class="col-xs-2">
Email
</div>
<div class="col-xs-10">
{{employee.email}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="panel-footer">
<button class="btn btn-primary" ng-click="viewEmployee(employee.id)">View</button>
<button class="btn btn-primary" ng-click="editEmployee(employee.id)">Edit</button>
<span ng-if="confirmDelete">
<span>Are you sure want to Delete?</span>
<button class="btn btn-danger" ng-click="deleteEmployee(employee.id)">Yes</button>
<button class="btn btn-primary" ng-click="confirmDelete=false">No</button>
</span>
<button class="btn btn-danger" ng-click="deleteConfirmation(employee.id)" ng-if="!confirmDelete">Delete</button>
</div>
{{confirmDelete}}
</div>
</div>
$scope.employeeList = employeeService.getListOfEmployees();
/**
* saveData
*/
$scope.saveData = function (employee) {
//Edit employee Information
if ($stateParams.employeeId != 0) {
var employee = employeeService.getEmployeeById($stateParams.employeeId);
employeeService.updateEmployee($stateParams.employeeId,employee);
} else {
employee.id = employeeService.getListOfEmployees().length + 1;
employeeService.addNewEmployee(employee);
}
$state.go('employeeList');
}
答案 0 :(得分:0)
当要传递给“ ng-repeat
”指令的数组中有重复对象时,AngularJS会引发上述异常。因此,您需要使用track by
,如下所示。您可以在模型数组对象中使用track by $index
或其他任何属性(例如track by employee.id
或track by employee.email
),这是唯一的。
试试下面的示例
<div ng-repeat="employee in employeeList | filter:{name:searchName} track by $index ">