我有ng-repeat
:
<option ng-repeat="year in data.dateList.year" ng-hide="year.id < limit" value="{{year.id}}" ng-selected="year.id == 0">
{{year.value}}
</option>
$scope.limit = 1991;
我尝试按条件隐藏选项:
ng-hide="year.id < limit"
不起作用
答案 0 :(得分:5)
使用filter:show
尝试这样做ng-repeat="year in data.dateList.year | filter:show"
JS
$scope.show=function(year){
return year.id > $scope.limit
}
如果你想得到索引
试试这个
$scope.show = function(year) {
console.log(getIndex($scope.data.dateList.year, year))
return year.id > $scope.limit
}
function getIndex(dataList, data) {
var index = -1;
dataList.some(function(item, i) {
if (JSON.stringify(item) == JSON.stringify(data)) {
index = i;
return true;
}
});
return index;
}