我有一个像这样的对象
a: 25.165562913907287
b: 25.274725274725274
c: 36.633663366336634
d: 2.6128266033254155
e: 55.52147239263804
f: 78.52941176470588
g: "xxx"
id: 6
现在我想使用角度j来显示带有从'a'到'g'的标题的表,排除字段'id',并且还显示从'a'到'g'的所有值,排除字段id,也不 我怎样才能做到这一点?
****注意**:我不想按属性值过滤属性本身,我做的是过滤器返回空字符串,如果字段等于'id',并寻找一个更好的解决方案
答案 0 :(得分:1)
查看打印出来的代码并添加if条件以跳过打印id
的列(略微修改gayathri的模板代码):
<table>
<thead>
<tr ng-repeat="item in arraylist | limitTo:1">
<th ng-repeat="(key, val) in item" ng-if="key!='id'">
<span>{{key}}</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in arraylist">
<td ng-repeat="(key, val) in item" ng-if="key!='id'">
{{val}}
</td>
</tr>
</tbody>
</table>
答案 1 :(得分:0)
假设从a到g和id的所有数据都分配给一些名为data
的varibaledata: {
a: 25.165562913907287
b: 25.274725274725274
c: 36.633663366336634
d: 2.6128266033254155
e: 55.52147239263804
f: 78.52941176470588
g: "xxx"
id: 6
}
现在用id,
排除id和关联值var excludedIdObject = {};
angular.forEach(data, function(key) {
if (data.id) {
return;
}
excludedIdObject = key;
}
答案 2 :(得分:0)
您好参考此https://plnkr.co/edit/ZGula5MLLyQ8Wd9c26Yc?p=preview
使用下划线中的Omit首先省略id然后使用该表来显示关键的dynamicaly和datas
$scope.arraylist = [
{
"id": 1,
"a": "jk",
"b": "May 5",
"c": "fgh",
"d": "true",
"e": "dfgdfg",
"f": "M",
"g": true,
"h": "Profile"
},
{
"id": 2,
"a": "ghfgh",
"b": "1 AM",
"c": "true",
"d": "true",
"e": "false",
"f": "47:11 AM",
"g": "true",
"h": "Profile"
},
{
"id": 3,
"a": "iyuiuy",
"b": " AM",
"c": "true",
"d": "true",
"e": "false",
"f": "Ma AM",
"g": "true",
"h": "Profile"
}
]
$scope.arraylist_duplicate = $scope.arraylist;
angular.forEach($scope.arraylist_duplicate , function(todo, i)
{
delete todo.id
});
<强> HTML 强>
<table>
<thead>
<tr ng-repeat="item in arraylist_duplicate | limitTo:1">
<th ng-repeat="(key, val) in item" >
<span>{{key}}</span>
</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in arraylist_duplicate ">
<td ng-repeat="(key, val) in item">
{{val}}
</td>
</tr>
</tbody>
</table>