searchKeyword 在 AngularJS 过滤器中不起作用

编程入门 行业动态 更新时间:2024-10-24 04:42:25
本文介绍了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:关键词]

本文发布于:2023-04-21 10:18:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1000481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   中不   searchKeyword   AngularJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!