【问题标题】:Angularjs How to show hidden data from the selected row in a listBox?Angularjs如何显示列表框中选定行的隐藏数据?
【发布时间】:2016-11-10 11:12:15
【问题描述】:

我得到了这样的东西:

一张表,里面有更多学生的数据...内容是 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;
};

现在的问题是,我的列表框显示了所选学生的帐户....但是他们都被选中了,一旦我按下其中一个,其他的就会消失,而按下的那个仍然被选中。 ...

最重要的是,一旦我去找另一个学生,然后回来...... listBox 中所有消失的帐户仍然不见了......而且旧的也被选中了......

最后我的问题是:

是否可以只选择学生,并且他的帐户会显示在列表框上而不被选择......并且在我按下它们后不会消失......?

提前谢谢!

【问题讨论】:

标签: javascript java angularjs data-binding listbox


【解决方案1】:

只需替换所选学生的变量即可。喜欢:

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

【讨论】:

  • 秒...我会试试的
猜你喜欢
  • 1970-01-01
  • 2017-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多