https://plnkr.co/edit/qUs7VH84QZGz0YlLJB70
上面的链接作为我的代码,当我点击保存按钮我得到保存,当我点击取消我输出错误,我的empID也只显示增加的计数值。我尽力解决;我想我没有得到它。
$scope.getTemplate = function (employee) {
if (employee.empID === $scope.selected.empID){
console.log(employee.empID);
console.log($scope.selected.empID);
console.log("edit");
return 'edit';
}
else {
console.log("display");
console.log(employee.empID);
console.log($scope.selected.empID);
return 'display';
}
};
我认为我在这个功能上出错,但无法找到我的错误。
答案 0 :(得分:1)
而不是更新插入的新行。
试试这个
$scope.updateEmployee = function(employee) {
var emp = $scope.employees.filter(function(x) {
return x.empID == employee.empID
});
if (emp.length > 0) {
emp[0].empID = employee.empID;
emp[0].empName = employee.empName;
emp[0].empEmail = employee.empEmail;
} else {
$scope.employees.push({
empID: employee.empID, //.length,
empName: employee.empName,
empEmail: employee.empEmail
});
}
//console.log($scope.employees.lenth);
//console.log($scope.employees);
$scope.reset();
//console.log($scope.reset());
$scope.getTemplate();
};
的 DEMO
强>