我需要在每个项目中添加复选框,并使用Angular.js获得多选值。我的代码如下。
<body ng-controller="speshController">
<h1>Hello</h1>
<div class="col-md-6">
<div class="input-group bmargindiv1 col-md-12">
<span class="input-group-addon ndrftextwidth text-right" style="width:180px">Child Business Name :</span>
<select class="form-control" multiple="multiple" id="restau" ng-model="restaurant" ng-options="qua.name for qua in listOfRestaurant track by qua.value" ng-change="getDayFromSpecial('restau');">
</select>
</div>
</div>
<button type="button" id="btn" ng-click="getValue();">GET</button>
</body>
这里我有一个下拉列表,我需要在下拉列表中的每个项目之前添加复选框。假设用户选择了多个项目,而它将单击GET
按钮,我需要获取这些选择的数据。我的控制器端代码如下所示。
app.controller('speshController',function($scope,$http){
$scope.data=[{
'value':1,
'name':'aaa'
},{
'value':2,
'name':'bvc'
},{
'value':3,
'name':'rtcv'
},{
'value':4,
'name':'uytg'
}
]
$scope.listOfRestaurant=[];
angular.forEach($scope.data,function(obj){
var data={'name':obj.name,'value':obj.value};
$scope.listOfRestaurant.push(data);
})
$scope.getValue=function(){
}
})
我需要在控制台中显示那些选定的数据。我的full code is here。
发布于 2016-11-01 15:39:25
ng-model on multi-select将为您提供所选项目作为数组
$scope.getValue=function(){
console.log($scope.restaurant)
}
发布于 2016-11-01 18:24:44
在我看来,最好使用带有标签的复选框,而不是多选下拉菜单。
<label ng-repeat="qua in listOfRestaurant track by qua.value">
<input type="checkbox" ng-model="qua.selected"/>
{{qua.name}}
</label>
您可以在Plunker中进行测试。
https://stackoverflow.com/questions/40355705
复制相似问题