2016-11-19 40 views
1

我想過濾ng-repeat與數組有字符串,如何使用多個過濾器或如何使用下面的數組直接過濾?過濾器重複與數組有字符串

濾波陣列:

["Fri, November 18th 2016","Sat, November 19th 2016","Sun, November 20th 2016","Mon, November 21st 2016","Tue, November 22nd 2016","Wed, November 23rd 2016","Thu, November 24th 2016"] 

JSP:在NG-重複使用

["Thu","Fri","Mon","Tue","Wed","Thu","Fri"] 

陣列

<div class="form-group" ng-repeat="vdates in view | filter : selecteddays "> 
+0

問題是什麼? –

+0

你不會問任何問題或說清楚你想要什麼 –

+0

我明確要求用含有字符串的數組過濾ng-repeat,第一個數組用於過濾,第二個用於使用ng-repeat迭代數據 –

回答

0

爲什麼不使用自己的自定義過濾功能,以檢查是否至少列表中的預期日期之一與您的輸入值相匹配?
我不確定我們可以通過內聯過濾來進行這種處理(指定數組和過濾條件爲:流和數組的任何元素之間至少有一個匹配)。

這是plunkr

HTML:

<!DOCTYPE html> 
<html ng-app="plunker"> 

    <head> 
    <meta charset="utf-8" /> 
    <title>AngularJS Plunker</title> 
    <script>document.write('<base href="' + document.location + '" />');</script> 
    <link rel="stylesheet" href="style.css" /> 
    <script data-require="[email protected]" src="https://code.angularjs.org/1.5.8/angular.js" data-semver="1.5.8"></script> 
    <script src="app.js"></script> 
    </head> 

    <body ng-controller="MainCtrl"> 
    <div class="form-group" ng-repeat="vdates in view | filter : myFilter"> 
     {{vdates}} 
    </div> 
    </body> 

</html> 

JS:

var app = angular.module('plunker', []); 

    app.controller('MainCtrl', function($scope) { 

     $scope.name = 'World'; 
     $scope.view = ["Fri, November 18th 2016","Sat, November 19th 2016", 
        "Sun, November 20th 2016","Mon, November 21st 2016", 
        "Tue, November 22nd 2016","Wed, November 23rd 2016", 
        "Thu, November 24th 2016" ]; 

     $scope.selecteddays=["Thu","Fri","Mon","Tue","Wed","Thu","Fri"]; 

     $scope.myFilter = function(value) { 

      if (!value){return false} 

      for (var i = 0; i < $scope.selecteddays.length; i++) { 
       currentAcceptedDay = $scope.selecteddays[i]; 
       if (value.indexOf(currentAcceptedDay) != -1) {       
        return true; 
       } 
      } 
      return false; 
     } 
    });