javascript - 使用 AngularJS 过滤单个列值

标签 javascript html angularjs

我创建了一个 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/

相关文章:

javascript - 纯 JS 中的两种方式数据绑定(bind)?

javascript - 使用 scrapy python 从 javascript 获取数据到 python

html - 初始规模的含义= 1.0

javascript - 使用带有 AngularJs 数据绑定(bind)的三元运算符显示图像

javascript - 复制 $sce 创建的对象并修改其值

angularjs - 如何使用Principal或Account服务获取当前登录的用户

javascript - 阻止本地 PHP/HTML 文件预览在服务器上执行 javascript

javascript - V-model 未绑定(bind)在 DOM 元素中

javascript - POST 表单只需要一个 select 标签

javascript - 从 javascript 创建 Bootstrap 下拉按钮