[英]jsfidle filter not working in angularjs
Here is the jsfiddle, i can get it to work with true, false values, but when i try to filter by name, it doesn't work any suggestions ? 这是jsfiddle,我可以使它与true,false值一起使用,但是当我尝试按名称过滤时,它没有任何建议吗?
<div ng-controller="MyCtrl">
<button class="btn" ng-click='filterCriteria={}'>All</button>
<button class="btn" ng-click='filterCriteria.read=true'>Read</button>
<button class="btn" ng-click='filterCriteria.title={{messages[0].title}}'>Foo</button>
<pre>{{messages[0].title}}</pre>
<hr/>
<table class="table table-bordered">
<thead>
<tr>
<td><strong>Title</strong></td>
<td><strong>Content</strong></td>
<td><strong>Read</strong></td>
</tr>
</thead>
<tbody>
<tr ng-repeat='message in messages |filter:filterCriteria'>
<td>{{message.title}}</td>
<td>{{message.content}}</td>
<td>{{message.read}}</td>
</tr>
</tbody>
</table>
</div>
function MyCtrl($scope) {
$scope.filterCriteria = {};
$scope.messages = [{
title: 'Foo',
content: 'Foo content',
read: false},
{
title: 'Bar',
content: 'Bar content',
read: true}
];
}
Since your filterCriteria is not cleared you are facing the issue. 由于未清除filterCriteria,因此您遇到了问题。
Try the below for filtering by name: 请尝试以下过滤名称:
$scope.filterByName= function(name){
$scope.filterCriteria={},
$scope.filterCriteria.title=name;
}
NOTE: I assume you are asking about new filtering when button is clicked and old filters are to be removed. 注意:我假设您在单击按钮并删除旧过滤器时询问新过滤器。
I think you don't need to use {{}} in ng-click 我认为您无需在ng-click中使用{{}}
use () 采用 ()
try 尝试
<button class="btn" ng-click='filterCriteria.title=(messages[0].title)'>Foo</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.