为什么我在表的所有行中获得相同的值。表具有行,单击行时,将打开另一行,其中包含其他信息,每行包含与上次单击的行相同的数据。可能是因为我在相同的对象中保存数据,但我真的不知道如何解决它。我从json
文件中获取带有因子的数据,因此您不会感到困惑,我的数据来自何处。这是代码。非常感谢你。
'use strict';
angular.module('sbAdminApp')
.controller('TreeTableCtrl', TreeTableCtrl);
function TreeTableCtrl($scope, $http, factor) {
function example() {
factor.getUse().then(function (response) {
$scope.users = response.data;
console.log($scope.users);
});
}
example();
$scope.togglePerson = function (index) {
factor.getChi().then(function (response) {
$scope.indx = index;
$scope.child = response.data;
console.log($scope.child);
$scope.childPar = $scope.child[index];
console.log($scope.childPar);
});
};
}
<div class="panel panel-default" style="background: #fcf8e3">
<div class="panel-body">
<table st-safe-src="leads" class="table table-hover ">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<tr ng-repeat-start="user in users track by $index" ng-init="parentIndex=$index"
ng-click="togglePerson($index); viewChild=!viewChild ">
<td> {{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.lastName}}</td>
</tr>
<tr ng-show="viewChild" ng-hide="indx!=$index" >
<td style="width: 450px">
<table class="table ">
<tbody>
<tr>
<th style="width: 200px">
Address
</th>
<td style="width: 200px">{{childPar.address}}</td>
<th style="width: 200px">
Number
</th>
<td style="width: 200px">{{childPar.mobNumb}}</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr ng-repeat-end></tr>
</tbody>
</table>
</div>
</div>