这就是我所拥有的:
<div data-ng-if="hasSelectedCompany">
<tbody data-ng-repeat="driver in result.applications | filter: { name: selectedApplication } track by $index">
</div>
<div data-ng-if="hasSelectedSupportedCompany">
<tbody data-ng-repeat="driver in result.applications | filter: { name: selectedSupportedApplication } track by $index">
</div>
我知道这可以改进,我只是不确定如何。它现在不能正常工作。当我在这里有这两个时,第一个表达式不起作用。当我完全删除第二个表达式时,第一个表达式开始工作。第二个适用于他们两个。
有什么方法可以实现这一目标?
谢谢!
答案 0 :(得分:2)
两个过滤器都无法一起使用,因为两者都指的是同一个result.applications
。
您需要将过滤后的数组分开,将其分配给applicationsForCompany
div&amp;的hasSelectedCompany
等不同变量。 applicationsForSupportedCompany
div
hasSelectedSupportedCompany
<强>标记强>
<div data-ng-if="hasSelectedCompany">
<tbody data-ng-repeat="driver in applicationsForCompany = (result.applications | filter: { name: selectedApplication }) track by $index">
</div>
<div data-ng-if="hasSelectedSupportedCompany">
<tbody data-ng-repeat="driver in applicationsForSupportedCompany = (result.applications | filter: { name: selectedSupportedApplication }) track by $index">
</div>
答案 1 :(得分:0)
<html ng-app="app">
<head>
<link rel="stylesheet" href="style.css">
<script src="https://code.angularjs.org/1.4.0/angular.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="mainCtrl">
<input type="text" ng-model="search">
<input type="text" ng-model="search1">
<div ng-repeat="d in data|filter:{name:search}">{{d.name}}</div>
<div ng-repeat="d in data|filter:{name:search1}">{{d.name}}</div>
</body>
</html>
angular.module('app',[]).controller('mainCtrl',['$scope',function($scope){
$scope.data = [{id:1,name:'cata',surname:'obreja'},{id:2,name:'dani',surname:'popa'},{id:3,name:'Sir',surname:'dani'}];
}]);
这是一个有效的例子,但我不确定它是否是您正在寻找的。 这是plnkr http://plnkr.co/edit/W7ZofMcZMKTfw3BUB4jX?p=preview