簡體   English   中英

篩選AngularJS中的多個屬性

[英]Filter through multiple properties in AngularJS

我正在嘗試過濾Angular中的多個屬性。 我可以通過使用filter:{ title: searchString }輕松地過濾一個屬性,但是當我嘗試使用多個屬性時……似乎根本沒有得到任何結果。

我需要做的是:

如果John Wayne是通過..通過它顯示John Wayne ,但如果只有John或僅Wayne通過......通過它仍顯示John Wayne 對於nw同樣如此,因為Johnn結束, subTitlew開頭

我的代碼:

<input type="text" ng-model="searchString">

<div ng-repeat="arr in arr1 | filter:{ title: searchString, subTitle: searchString }"></div>

$scope.arr1 = [
    {title: 'John',subTitle:'Wayne'}
    {title: 'Barry'}
];

 var app = angular.module("app", []); app.controller("ListCtrl", ["$scope", function($scope) { $scope.arr1 = [ {title: 'John',subTitle:'Wayne'}, {title: 'Barry'} ]; } ]); 
 <!DOCTYPE html> <html> <head> <script data-require="angular.js@1.4.7" data-semver="1.4.7" src="https://code.angularjs.org/1.4.7/angular.js"></script> <link rel="stylesheet" href="style.css" /> <script src="script.js"></script> </head> <body ng-app='app'> <div ng-controller="ListCtrl"> title:<input type="text" ng-model="criteria.title"> subtitle:<input type="text" ng-model="criteria.subTitle"> <br> <div ng-repeat="arr in arr1 | filter: criteria">{{arr}}</div> </div> </body> </html> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM