我正在尝试过滤Angular中的多个属性。我可以使用filter:{ title: searchString }
轻松过滤一个属性,但是当我尝试使用多个属性时......它似乎根本没有得到任何结果。
我需要做的是:
如果John Wayne
通过..它会显示John Wayne
,但如果仅John
或仅Wayne
通过...它仍会显示John Wayne
。同样适用于n w
,因为John
以n
结尾,subTitle
以w
开头
我的代码:
<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'}
];
答案 0 :(得分:1)
var app = angular.module("app", []);
app.controller("ListCtrl", ["$scope",
function($scope) {
$scope.arr1 = [
{title: 'John',subTitle:'Wayne'},
{title: 'Barry'}
];
}
]);
&#13;
<!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>
&#13;