gpt4 book ai didi

javascript - AngularJS 如何取消选择 ComboBox 中的所有内容?

转载 作者:行者123 更新时间:2023-11-30 15:42:35 26 4
gpt4 key购买 nike

好的伙计们,我有这样的东西:

         <select style="width: 100px;"
ng-disabled="true"
ng-model="selectedStudent.accounts"
size="5"
ng-options="accounts.name for acount in selectedStudent.accounts track by account.id"
>
</select>

长话短说......它工作得很好,在页面上......它显示了我需要的所有数据......但是第一个空行被选中(它是蓝色的,而其他的是灰色的(禁用)) ...就像下面的例子一样:

帐户:

row0 (selected and empty)

row1 (real data in it, and disabled)

row2 (real data in it, and disabled)

row3 (real data in it, and disabled)

现在我需要去掉第一行……它根本不应该在那里……什么都不应该选择...

有什么建议吗?

这里是一些更多的数据:

    $scope.selectedStudent = {};
$scope.selectedStudent = student;

和学生:

他有 Id,Name 和 Last Name,还有 BankAccount

@OneToMany(cascade = { CascadeType.ALL})
private Set<BankAccount> accounts;

public Student() {
accounts= new HashSet<BankAccount>();
}

最佳答案

试试这个:-

angular.module('app', [])
.controller('Controller', function($scope) {

$scope.selectedStudent = {};
$scope.selectedStudent.accounts = {};
$scope.selectedStudent.accounts[0] = {};
$scope.selectedStudent.accounts[0].name = "first";
$scope.selectedStudent.accounts[0].id = 1;
$scope.selectedStudent.accounts[1] = {};
$scope.selectedStudent.accounts[1].name = "second";
$scope.selectedStudent.accounts[1].id = 2;
$scope.selected_account = $scope.selectedStudent.accounts[0].id;
})
<!DOCTYPE html>

<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<script src="script.js"></script>
</head>

<body ng-app="app">
<div ng-controller="Controller">
<select style="width: 100px;" ng-disabled="true" ng-model="selectedStudent.accounts" size="5" ng-options="acount.name for acount in selectedStudent.accounts track by acount.id">
<option value="" selected hidden />
</select>

</div>
</body>

</html>

关于javascript - AngularJS 如何取消选择 ComboBox 中的所有内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40585954/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com