在这里,从json开始,它将显示数量。根据数量值,选择需要动态生成如下。
答案 0 :(得分:2)
您可以limitTo
与ng-options
一起动态展示options
元素<{1}}
select
angular.module("app", []).controller("myCtrl", function($scope) {
$scope.selectedItem = 1;
$scope.list = [1, 2, 3, 4];
$scope.quantity = 1;
});
答案 1 :(得分:0)
至于对问题的理解,您可以创建自定义过滤器,根据数量过滤掉选项。
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.obj = {
"list": [
{
"quantity": [
2,
3,
4
]}
]}
})
.filter('cust',function(){
return function(item){
var arr = []
for(var i =1; i<= parseInt(item); i++){
arr.push(i)
}
return arr
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="q in obj.list">
<div ng-repeat="i in q.quantity">
<select ng-init="q.selectval[i] = i" class="classname" ng-model="q.selectval[i]" ng-options="value as value for (key,value) in i | cust" >
</select>
{{q.selectval[i]}}
</div>
</div>
</div>