简体   繁体   English

使用angularJS过滤器搜索另一个对象

[英]Using angularJS filter to search in another object

I want to use the Angular filter on ng-repeat to search in another object, not the object used in the ng-repeat. 我想对ng-repeat使用Angular过滤器来搜索另一个对象,而不是ng-repeat中使用的对象。 Can I do that or there is a better way to do that. 我可以这样做还是有更好的方法来做到这一点。

Here is a Plunker link . 这是一个Plunker 链接

I want to search in the all_data object not sample_data. 我想在all_data对象而不是sample_data中搜索。

You can use this trick: 您可以使用以下技巧:

<div ng-init="filteredItems = all_data"/>

<input ng-model="searchText" ng-change="filteredItems = (all_data | filter: searchText)">

At start, filteredItems equals all_data . 开始时, filteredItems等于all_data When input searchText changed, filteredItems changed too. 输入searchText更改时, filteredItems更改。

You can use {{filteredItems}} on the view, and $scope.filteredItems in the controller. 您可以在视图上使用{{filteredItems}} ,并在控制器中使用$scope.filteredItems

I adjust your plunker, please see it. 我调整了您的插头,请看一下。

Plunker 柱塞

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

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