我有一组数据,如11112344411121,每个整数代表4个类别ID。它将从后端加载。所以我使用函数countState
对它进行计数和分类。
$scope.countState = function(){
$scope.countNote = 0;
$scope.countQuote = 0;
$scope.countProject = 0;
$scope.countSkill = 0;
for(var i = 0;i< $scope.postItem.length;i++){
$loopObj = $scope.postItem[i].category_id;
switch($loopObj)
{
case '1':
$scope.countNote++;
break;
case '2':
$scope.countQuote++;
break;
case '3':
$scope.countProject++;
break;
case '4':
$scope.countSkill++;
break;
}
}
}
我有另一个功能,当用户插入内容时会更新。 {{countNote}}未更新。为什么? $ scope问题?
$scope.updateState = function(currentTab){
alert(currentTab);
switch(currentTab)
{
case '1':
$scope.countNote++;
break;
case '2':
$scope.countQuote++;
break;
case '3':
$scope.countProject++;
break;
case '4':
$scope.countSkill++;
break;
}
}
或者我应该在后端算一下?