我创建了一个AngularJS应用程序,其中包含一个用于过滤<tbody>
的<tr>
的输入。使用AngularJS在单列值上过滤
现在我的表正在过滤国家和城市 - 我希望它只在国家过滤。我已经尝试了很多filter:{Country: Search}
的变体,但它似乎没有工作。
由于用户edisoni.1337我有使用AngularJS 1.2.1(低于一个可见)的更新的工作示例。
var app = angular.module('myApp', []);
app.controller('callCtrl', function($scope)
{
\t $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>
CDN为1.5.6:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
很奇怪 - 你的例子似乎是工作的jsfiddle,但我可以”不要让它在本地工作,尽管代码是相同的。任何线索? – Daniel
我现在看到由于某些原因,这只适用于角js 1.0.1版本,你已经包含在jsfiddle。 –
我认为这是因为你正在使用的多维数组,因为我尝试使用一维数组,并且它的工作原理很好 –