【问题标题】:AngularJS binding issue in ngRepeat (Collapse and Expand Caret)ngRepeat 中的 AngularJS 绑定问题(折叠和展开插入符号)
【发布时间】:2015-12-02 22:27:05
【问题描述】:

我正在尝试在 ngRepeat 中实现折叠和展开面板。我试过这个:

<tbody ng-repeat="item in Items">
    <tr data-toggle="collapse" class="accordion-toggle">
        <td>{{item.name}}</td>
        <td>
        <a class="dropdown-toggle" ng-click="isCollapsed = !isCollapsed;getDetails(item.id);" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="caret"></span></a>
        </td></tr>
    <tr>
        <td class="hiddenRow">
            <div class="accordian-body collapse" collapse="isCollapsed">
            <table class="table display" style="border-collapse:collapse;">
                <thead><tr>
                <th>Student Name</th><th>Roll Number</th></tr></thead>
                <tbody>
                <tr>
                    <td>{{studentRecord.patientName}}</td><td>{{studentRecord.rollNumber}}</td>
                </tr></tbody></table>
            </div>
        </td>
    </tr>  
</tbody>

脚本:

$scope.getDetails = function (sId)
    {

    var studentDetails = DetailService.getDetail("studentsDetails", sId);
    studentDetails.then(function(data) {
                $scope.studentRecord = data;
         });    
    }

当我单击 ngRepeat 中的单个插入符号按钮时,它工作正常。但是,当我单击多个项目时,转发器会为每个项目创建一个范围。因此,ngRepeat 中的所有记录都获得相同的范围值。如何解决。

【问题讨论】:

  • 你问的是 $scope.studentRecord = data;总是一样的?
  • 没有。当我展开多条记录时,$scope.studentRecord 为所有记录附加相同的值。
  • 尝试在下面使用我的代码 :)

标签: javascript angularjs twitter-bootstrap


【解决方案1】:

你应该在像这样的项目中创建属性

item.studentRecord 

然后使用

获取详细信息(项目)

$scope.getDetails = function (item)
    {

    var studentDetails = DetailService.getDetail("studentsDetails", item.id);
    studentDetails.then(function(data) {
                item.studentRecord = data;
         });    
    }

<td>{{item.studentRecord.patientName}}</td>
<td>{{item.studentRecord.rollNumber}}</td>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    • 2016-11-02
    • 2011-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多