简体   繁体   English

使用过滤器的AngularJS搜索

[英]AngularJS Search using Filter

I am trying to have a search box search values in a table. 我试图在表中有一个搜索框搜索值。 My code currently works fine. 我的代码目前可以正常工作。

<tr ng-repeat="b in bugs | filter:searchText">

However, I wish to go further and give users the ability to search specific columns if they have a colon in their search text (eg "id: 3"). 但是,我希望走得更远,如果用户在搜索文本中带有冒号(例如,“ id:3”),则可以让他们搜索特定的列。

I have managed to split the search text, separating the column name from the field text. 我设法拆分了搜索文本,从字段文本中分离出列名。

I read in AngularJS you can do searchText.id to filter specific columns. 我在AngularJS中阅读,您可以执行searchText.id来过滤特定的列。 However, my table has quite a few columns and I only have a string of the column name. 但是,我的表有很多列,并且我只有一个列名称字符串。

My question is, what is the best way to dynamically set the column being filtered? 我的问题是,动态设置要过滤的列的最佳方法是什么?

Access the column you're searching by accessing it with array syntax. 通过使用数组语法访问要搜索的列。

searchText.id; 
var columnName = "id";
searchText[columnName]; // same thing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM