2016-11-14 39 views
1

好球員,我得到了這樣的事情:AngularJS如何在ComboBox中取消全部選擇?

  <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; 

和學生:

他有身份證,名字和姓氏,還有的BankAccount

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

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

你想要默認的選擇選項嗎? – Chetan

+0

不,我只想顯示數據...並且必須全部禁用 – newbie

+0

您能共享selectedStudent.accounts的json格式嗎請 – Chetan

回答

2

試試這個: -

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>

+1

這個作品! thx人 – newbie