gpt4 book ai didi

javascript - Angular 空选项删除

转载 作者:行者123 更新时间:2023-11-28 00:08:51 24 4
gpt4 key购买 nike

当我重复数组时,我遇到了空选项的问题。这是代码。

查看:

<select  ng-model="getseason" class="form-control">
<option ng-repeat="season in seasons" value="{{ season }}">
Season {{ season + '/' + seasonaddone(season) }}
</option>
</select>

型号:

$scope.getseason={};

$scope.seasons = [2014,2013,2012,2011,2010,2009,2008,2007,2006,2005];

$scope.getseason = $scope.seasons[0];

$scope.seasonaddone = function(season){
return ++season;
}

$scope.$watch('getseason',function(){
console.log($scope.getseason);
console.log(typeof $scope.getseason);
});

如何删除空选项?我发现很多类似的问题,但我找不到解决方案。

最佳答案

尝试使用ngOptions而不是 ngRepeat

尝试这样

<select  ng-model="getseason" class="form-control" ng-options="season  as 'Season '+ season + '/' + seasonaddone(season)  for season in seasons">
</select>

关于javascript - Angular 空选项删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31090087/

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