2016-11-14 42 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