我有这样的东西:
一张表,包含更多学生的数据...内容是 ID、Name、LastName 和 From...现在我向项目添加了一个新类...它称为 BankAccount
学生可以拥有 0 个或多个帐户...
我将它们添加到学生的数据绑定(bind)过程中......
现在我想选择一个学生,并在同一页面的列表框中显示他的(如果有)帐户...到目前为止我有以下代码:
与学生的 table ...
<table border="1" name="tableStud" arrow-selector>
<tbody>
<tr>
<td>ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>From</td>
</tr>
<tr ng-repeat="student in result"
ng-class="{'selected':$index == selectedRow}"
ng-click="setSelected(student,$index)">
<td>{{ student.id }}</td>
<td>{{ student.firstname }}</td>
<td>{{ student.lastname }}</td>
<td>{{ student.mestorodjenja.ime }}</td>
</tr>
</tbody>
</table>
<select ng-model="student.accounts" multiple="multiple"
ng-options="account.name for account in student.accounts track by account.id"
>
</select>
在 Controller 中我得到了这个:
$scope.setSelected = function(student, index) {
$scope.student = student;
$scope.selectedRow = index;
};
现在的问题是,我的列表框显示了所选学生的帐户......但它们都已选择,一旦我按下其中一个,其他帐户就会消失,而按下的那个仍处于选中状态。 ...
最重要的是,一旦我转到另一名学生,然后回来...列表框中所有消失的帐户仍然丢失...并且旧帐户也被选中...
最后我的问题是:
是否可以只选择学生,并且他的帐户在不被选择的情况下显示在列表框中......并且在我按下它们后不会消失......?
提前致谢!
最佳答案
只需替换所选学生的变量即可。喜欢:
$scope.setSelected = function(student, index) {
$scope.selectedstudent = student;
$scope.selectedRow = index;
};
HTML:
<select ng-model="student.accounts" multiple="multiple"
ng-options="account.name for account in selectedstudent.accounts track by account.id">
</select>
关于javascript - Angularjs 如何显示列表框中所选行的隐藏数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40526182/