我有这样一个JSON,我想它的标志值集团和领域
$scope.staffs = [
{
"id": 1,
"name": "Management",
"Flag": 1
},
{
"id": 2,
"name": "Revenue Collection/Ledger",
"Flag": 1
},
{
"id": 3,
"name": "Office Assistance",
"Flag": 1
},
{
"id": 4,
"name": "Operators (Source)",
"Flag": 2
},
{
"id": 5,
"name": "Operators (WTP)",
"Flag": 2
},
{
"id": 6,
"name": "Operators at Networks",
"Flag": 2
}
]
计算字段的总和,组和我的HTML是这样在这里我想要什么当用户把价值常驻现场应该找到它标志值,并计算常驻领域的总和与标志值,如果标志值是1个放总和wspStaffTotal.Admin_Perm_Total,如果标志值是2将总和wspStaffTotal .Technical_Perm_Total
<div ng-repeat="wspStaffTbl in staffs">
{{ wspStaffTbl.name }}
<input type="text" ng-model="wspStaffTbl.Permanent" ng-change="updatePermanentTotal()">
</div>
<input type="text" ng-model="wspStaffTotal.Admin_Perm_Total">
<input type="text" ng-model="wspStaffTotal.Technical_Perm_Total">
是我的尝试是
$scope.updatePermanentTotal = function(){
$scope.wspStaffTotal.Admin_Perm_Total = 0;
$scope.wspStaffTotal.Technical_Perm_Total = 0;
angular.forEach($scope.staffs, function(value, key){
if(!isNaN(parseInt(value.Permanent))){
if(value.Flag==1){
$scope.wspStaffTotal.Admin_Perm_Total = $scope.wspStaffTotal.Admin_Perm_Total + parseInt(value.Permanent);
}
if(value.Flag==2){
$scope.wspStaffTotal.Technical_Perm_Total = $scope.wspStaffTotal.Technical_Perm_Total + parseInt(value.Permanent);
}
}
})
}
但预计它无法正常工作。
运行在每此功能陈ge会花费你很多的表现... –
是啊我知道有没有其他方式? – sanu
反跳才能解决您的性能问题... https://lodash.com/docs/4.16.4#debounce –