javascript - Angularjs 如何显示列表框中所选行的隐藏数据?

标签 javascript java angularjs data-binding listbox

我有这样的东西:

一张表,包含更多学生的数据...内容是 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/

相关文章:

javascript - 有希望的 API 回调 - 如何正确解决或拒绝

angularjs - 如果{{user.userName}}为空,我可以在div中显示替代文本吗?

javascript - 从数据 uri 下载文本文件时如何更改文件名和扩展名

javascript - 更改 D3 定向力图中箭头标记的方向

javascript - 为什么不总是使用索引作为 vue.js for 循环中的键?

Java 8 Base64 编码(基本)不再添加新行。我怎样才能重新实现这个?

java - 使用 REST-assured 验证响应 header 中的整数值

java - 如何从单个 CallableStatement 获取多个结果集?

AngularJS 工厂参数

javascript - 将 Javascript 添加到 php 代码