我创建了一个 AngularJS 应用程序,其输入用于过滤 <tbody>
的<tr>
.
现在我的表格正在按国家和城市进行过滤 - 我希望它仅按国家/地区进行过滤。我尝试了 filter:{Country: Search}
的很多变体但似乎不起作用。
Thanks to user edisoni.1337 I have an updated working example using AngularJS 1.2.1 (the one seen below).
var app = angular.module('myApp', []);
app.controller('callCtrl', function($scope)
{
$scope.stuff = [{"House": {"Country": "Denmark", "City": "Copenhagen"}}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<div ng-app="myApp" ng-controller="callCtrl">
<input type="text" ng-model="Search">
<table>
<thead>
<tr>
<th>Country</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="x in stuff | filter : {'House.Country' : Search}">
<td>{{x.House.Country}}</td>
<td>{{x.House.City}}</td>
</tr>
</tbody>
</table>
</div>
1.5.6 的 CDN:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
最佳答案
这里有一个工作 jsfiddle
<tr ng-repeat="x in stuff | filter : {'House.Country' : Search}">
<td>{{x.House.Country}}</td>
<td>{{x.House.City}}</td>
</tr>
Also read this article for better understand http://www.w3schools.com/angular/ng_filter_filter.asp
关于javascript - 使用 AngularJS 过滤单个列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39058871/