Javascript 表'中的重复数据;s行,角形
为什么我在表的所有行中得到相同的值。表中有行,当单击行时,会打开另一行,其中包含附加信息,并且每一行包含与上次单击的行相同的数据。可能是因为我在同一个对象中保存数据,但我真的不知道如何解决它。我使用factor从json文件中获取数据,所以您不会混淆我的数据来自何处。这是代码。多谢各位Javascript 表'中的重复数据;s行,角形,javascript,angularjs,Javascript,Angularjs,为什么我在表的所有行中得到相同的值。表中有行,当单击行时,会打开另一行,其中包含附加信息,并且每一行包含与上次单击的行相同的数据。可能是因为我在同一个对象中保存数据,但我真的不知道如何解决它。我使用factor从json文件中获取数据,所以您不会混淆我的数据来自何处。这是代码。多谢各位 “严格使用”; 角度.module('sbAdminApp') .controller('TreeTableCtrl',TreeTableCtrl); 函数TreeTableCtrl($scope、$http、
“严格使用”;
角度.module('sbAdminApp')
.controller('TreeTableCtrl',TreeTableCtrl);
函数TreeTableCtrl($scope、$http、factor){
$scope.nonCollapsedUser=[];
var getUsers=函数(){
factor.getUse().then(函数(响应){
$scope.users=response.data;
});
};
getUsers();
var getUsersInfo=函数(){
factor.getChi().then(函数(响应){
$scope.child=response.data;
log($scope.child);
});
};
getUsersInfo();
$scope.togglePerson=函数(索引){
$scope.nonCollapsedUser.push(索引);
$scope.newObj=$scope.child[index];
log($scope.newObj);
};
$scope.hidePerson=函数(索引)
{
对于(var i=0;i根据您的描述,
我假设你的用户,像这样的子数组
$scope.users =[
{"id":1,"name":"Mirko","lastName":"Spriko"},
{"id":2,"name":"Pero","lastName":"Peric"},
{"id":3,"name":"Marko","lastName":"Prezime"}
];
$scope.child =[
{"address":"Address1","mobNumb":"47423756324"},
{"address":"Address2","mobNumb":"73454635545"},
{"address":"Address3","mobNumb":"87464343648"}
];
首先,您需要将子对象映射到用户
angular.forEach($scope.users, function(value,key){
value.child =$scope.child[key];
});
现在你可以实现你的目标了
<table st-safe-src="leads" class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Last Name</th>
<th></th>
</tr>
</thead>
<tbody ng-repeat="user in users" >
<tr>
<td>{{user.id}}</td>
<td>{{user.name}}</td>
<td>{{user.lastName}}</td>
<td>
<button ng-show="nonCollapsedUser.indexOf($index) == -1" class="btn" ng-click="togglePerson($index)">
<i class="fa fa-arrow-down"></i>veiw</button>
<button ng-show="nonCollapsedUser.indexOf($index) > -1" class="btn" ng-click="hidePerson($index)"><i
class="fa fa-arrow-up"></i>hide</button>
</td>
</tr>
<tr ng-show="nonCollapsedUser.indexOf($index) > -1">
<td></td>
<td>{{user.child.address}}</td>
<td>{{user.child.mobNumb}}</td>
<td
</tr>
</table>
身份证件
名称
姓
{{user.id}
{{user.name}
{{user.lastName}
面纱
隐藏
{{user.child.address}
{{user.child.mobNumb}
每次调用togglePerson
时,您都超出了$scope.newObj
,并且每个未折叠的行都将显示最后一个$scope.newObj
以这种方式创建的。例如,您可以将数据存储在用户
对象中。如果要显示多行附加信息,则需要将数据存储在user对象。如果您只想显示一行附加信息,则需要关闭上一个打开的行。因为您使用的是同一个newObj。@Dushyantha我想同时显示多行附加信息。请您确切地告诉我哪一行中有哪些数据,我是AngularAwesome,tnx mate:D的新成员