angularjs – 如何使用Angular JS将值推送到数组中检查uniquness?

前端之家收集整理的这篇文章主要介绍了angularjs – 如何使用Angular JS将值推送到数组中检查uniquness?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
$scope.displayyears = [];
  $scope.Joinyear = function(display) {
    $scope.yeardisplay = display;       
    $scope.yeardisp = $scope.displayyears.push($scope.yeardisplay);
    $scope.displayyeaRSS = uniq($scope.yeardisp)
  }

它会抛出错误,如“uniq is undefined”..我们如何检查唯一性?

添加之前,请尝试检查yeardisplay是否已经在阵列中
$scope.displayyears = [];
$scope.Joinyear=function(display){
     $scope.yeardisplay=display;        
     if ($scope.displayyears.indexOf(display) == -1) {
         $scope.displayyears.push(display);
     }
}

猜你在找的Angularjs相关文章