gpt4 book ai didi

angularjs - 如何在使用 Angular JS 将值插入数组时检查唯一性?

转载 作者:行者123 更新时间:2023-12-03 23:23:23 24 4
gpt4 key购买 nike

  $scope.displayyears = [];
$scope.Joinyear = function(display) {
$scope.yeardisplay = display;
$scope.yeardisp = $scope.displayyears.push($scope.yeardisplay);
$scope.displayyearss = uniq($scope.yeardisp)
}

它会抛出诸如“uniq 未定义”之类的错误……我们如何检查唯一性?

最佳答案

在添加之前尝试检查 yeardisplay 是否已经在数组中

$scope.displayyears = [];
$scope.Joinyear=function(display){
$scope.yeardisplay=display;
if ($scope.displayyears.indexOf(display) == -1) {
$scope.displayyears.push(display);
}
}

关于angularjs - 如何在使用 Angular JS 将值插入数组时检查唯一性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14600523/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com