$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); } }