本文介绍了searchKeyword 在 AngularJS 过滤器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
限时送ChatGPT账号..我正在前端使用 AngularJS 编写应用程序.我想通过任何单词/字段搜索表格;一个搜索框搜索所有内容.根据这里的这篇文章:http://hello-angularjs.appspot/searchtable我可以使用 filter: searchKeyword 来做到这一点.
I am writing an app using AngularJS on the front end. I want to search through a table by any word/field; one search box for everything. According to this article here: http://hello-angularjs.appspot/searchtable I can use filter: searchKeyword to do just this.
这是我的代码,它没有按预期工作.
This is my code, and it is not working as expected.
<label>Search: <input ng-model="searchKeyword"></label>
<table ng-repeat="post in posts | orderBy: sort | filter: searchKeyword">
<tr>
<td> {{index(post)}} </td>
<td> {{post.title}} </td>
<td> {{post.author}} </td>
<td> {{post.content}} </td>
<td> {{post.date | date: "d/M/yyyy"}} </td>
</tr>
</table>
我该怎么办?谢谢
推荐答案
试试这个:
控制器
$scope.posts = [
{title:'Title one', author:'Author one', content: 'Content one'},
{title:'Title two', author:'Author two', content: 'Content two'},
{title:'Title three', author:'Author three', content: 'Content three'}
];
$scope.searchKeyword = '';
$scope.sort = 'title';
查看
<label>Search:
<input ng-model="searchKeyword">
</label>
<table ng-repeat="post in posts | orderBy: sort | filter: searchKeyword">
<tr>
<td> {{post.title}} </td>
<td> {{post.author}} </td>
<td> {{post.content}} </td>
</tr>
</table>
这篇关于searchKeyword 在 AngularJS 过滤器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论