我有這樣一個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 –