我正在使用angularJS开展一些项目并且我坚持这个问题。我有一个问题,它是关于angularJS中的过滤器。我不知道如何从JSON过滤一个特定的属性。
以下是我的索引页面的一部分
的index.html
<div class="container2">
<table class="table table-hover" ng-hide="hideTable2">
<tr>
<th>Site URL</th>
<th>Group</th>
<th>Edit</th>
</tr>
<tr ng-repeat="site in promise.sites | filter:{group:[""]}" >
<td>
<a href="http://{{site.url}}" style="color:{{site.color}}; text-decoration:none">
{{ ::site.siteName }} </a>
<td>
<div class = "btn-group">
<button type = "button" class = "btn btn-primary"> Groups
<span class="badge">{{ ::site.group.length }}</span>
</button>
<button type = "button" class = "btn btn-primary dropdown-toggle" data-toggle = "dropdown">
<span class = "caret"></span>
<span class = "sr-only">Toggle Dropdown</span>
</button>
<ul class = "dropdown-menu" role = "menu" >
<li ng-repeat="g in site.group"><span>{{::g}}</span><hr></li>
</ul>
</div>
<td>
<button class="btn btn-primary" ng-click="toggleEditSites()">Edit</button>
</td>
<td>
<img src="images/glyphicons-208-remove.png" ng-click="deleteSites(site.id)"/>
</td>
</tr>
</table>
这是JSON结构:
data.json
{
"sites":[
{
"id": 1,
"siteName":"Google",
"url": "www.google.com",
"color": "green",
"group": ["Social","Sport","Games","News","Programming"]
},
{
"id": 2,
"siteName":"Facebook",
"url": "www.facebook.com",
"color": "blue",
"group": []
},
{
"id": 3,
"siteName":"B92",
"url": "www.b92.net",
"color": "red",
"group": ["Social","Sport"]
},
{
"id": 4,
"siteName":"9GAG",
"url": "www.9gag.com",
"color": "purple",
"group": []
}
],
"groups":[
{
"id":1,
"name":"Search Engine",
"color":"green",
"sites":["Google","Yahoo","Bing"]
},
{
"id":2,
"name":"Social",
"color":"red",
"sites":[]
},
{
"id":3,
"name":"Games",
"color":"blue",
"sites":[]
},
{
"id":4,
"name":"Informations",
"color":"red",
"sites":[]
},
{
"id":5,
"name":"Sport",
"color":"orange",
"sites":[]
},
{
"id":6,
"name":"Television",
"color":"green",
"sites":[]
}
]
}
我想在&#34; sites&#34;中按组属性进行过滤如果有人能向我解释这一点,我会很高兴。非常感谢你。