我創建了一個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。 –
我認爲這是因爲你正在使用的多維數組,因爲我嘗試使用一維數組,並且它的工作原理很好 –