我正在前端使用AngularJS编写应用程序。我希望通过任何单词/字段搜索表格;一切都有一个搜索框。根据这篇文章:http://hello-angularjs.appspot.com/searchtable 我可以使用filter:searchKeyword来做到这一点。
这是我的代码,并没有按预期工作。
<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>
我该怎么办?谢谢
答案 0 :(得分:1)
试试这个:
<强>控制器强>
$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>
答案 1 :(得分:0)
我自己遇到了类似的问题。
我做了类似的事
<input class="form-control" type="text" ng-model="searchFilter.itemDesc"
placeholder="Search...." />
<tr ng-repeat="item in items | filter: searchFilter">
每个项目都具有itemDesc
的属性这种方法的缺点是它只允许你搜索正在重复的对象的一个属性
如果您希望通过对象的不同属性进行搜索
你可以做类似的事情
Filtering by Multiple Specific Model Properties in AngularJS (in OR relationship)