如何在AngularJS中使用多选选择框

时间:2015-06-09 11:41:05

标签: javascript angularjs

表格结构

ID Name
1  milk
2  flour
4  sugar
8  salt
16 eggs
32 butter

 <select multiple ng-click="FilterIngredients" ng-model="model.ID" ng-options="items.ID as items.Name for items in model.Ingredients " required>
  <option selected disabled value=""></option>
  </select>

如何从选择框中选择多个选项而无需按住ctrl按钮?我想只传递其余的最高ID,如果用户先点击黄油然后再点奶,那么黄油的ID必须返回32

控制器

$scope.FilterIngredients = function (item) {};

1 个答案:

答案 0 :(得分:0)

有几种方法可以做到这一点:

使用凉亭:

bower install angularjs-dropdown-multiselect

HTML

<div ng-dropdown-multiselect="" options="example1data" selected-model="example1model"></div>

控制器

$scope.example1model = [];  
$scope.example1data = [ {id: 1, label: David"}, {id: 2, label: "Jhon"},{id: 3, label: "Danny"}];