[英]How do I reset a select list in AngularJS and track by?
我有一個選擇列表。
<select id="search.month"
ng-model="search.month"
class="form-control"
ng-options="item as item.name for item in months track by item.id">
</select>
我重置了列表
$scope.reset = function () {
$scope.search = {reportType: 0, month: 0, year: 0 };
};
什么都不會發生。 AngularJS 1.5.8
AngularJs 1.4 + 中存在一個錯誤。 根據我的經驗,至少達到 1.5.8。
使用 jQuery 手動重置列表。 忽略 angularJS。
$scope.reset = function () {
$scope.search = {reportType: 0, month: 0, year: 0 };
// Manually reset.
// https://github.com/angular/angular.js/issues/14892
$('#search\\.month').find('> option').each(function() {
$(this).removeAttr('selected');
});
$('#search\\.year').find('> option').each(function() {
$(this).removeAttr('selected');
});
};
你需要調用這個函數:
$scope.resetDropDown = function() {
$scope.temp = $scope.search.month; // Before reset select box, get selected value
$scope.search.month = "";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.