繁体   English   中英

Angular.js如何显示列表框中选定行的隐藏数据?

[英]Angularjs How to show hidden data from the selected row in a listBox?

我有这样的事情:

一个包含更多学生数据的表格...内容是ID,Name,LastName和From .....现在我向该项目添加了一个新班级...其名为BankAccount

学生可以拥有0个或更多帐户...

然后我在数据绑定过程中将它们添加到了学生中...

现在我想选择一个学生,并在同一页面上的列表框中显示他的帐户(如果有)...到目前为止,我有以下代码:

与学生同桌...

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

在控制器中,我得到了:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM