我在 HTML 中使用 ng-repeat 在 javascript 数组上循环。在选择中显示此数组。 我想要做的是在按下按钮时从这些下拉列表中清除所有选定的数据
HTML
<div class="widget-title">
<div class="widget-controls">
<button class="btn btn-xs btn-primary" ng-click="newassignment()">New</button>
<button class="btn btn-xs btn-success" ng-click="saveavd()">Save</button>
</div>
<h3><i class="icon-ok-sign"></i>Assignment</h3>
</div>
<div id="vacation" class="widget-content" style="height:81vh; overflow:auto;">
<div class="row">
<table style="width: 70%;" border="1">
<thead>
<tr>
<th>Departments</th>
<th>Work Level</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="d in departments | filter : depts">
<td>
<input style=" margin-top: 0;" type="checkbox" ng-model="d.details"/> {{d.Dep_LDesc}}
</td>
<td>
<select class="form-control input-sm" ng-model="wrklevel2">
<option ng-repeat="w in worklevel" value="{{w.lvlid}}">{{w.lvlnm}}</option>
</select>
</td>
</tr>
</tbody>
</table>
Angular
$scope.worklevel = [
{ lvlid: 1, lvlnm: 'First Level' },
{ lvlid: 2, lvlnm: 'Second Level' }
]
$scope.newassignment = function () {
$scope.wrklevel2 = {};
angular.forEach($scope.departments, function (d) {
d.details = false;
})
}
最佳答案
您应该在 ng-repeat 中为您的选择设置不同的模型,以实现您可以尝试以下操作
(ng-model="d.wrklevel2")
<select class="form-control input-sm" ng-model="d.wrklevel2">
<option ng-repeat="w in worklevel" value="{{w.lvlid}}">{{w.lvlnm}}</option>
</select>
之后您还可以清除 forEach 循环中的 select 值
angular.forEach($scope.departments, function (d) {
d.details = false;
d.wrklevel2 = undefined;
})
关于javascript - 如何清除angularjs中下拉列表的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54784231/