如何过滤 ui-grid 中的多个值? (angularjs)

How to filter with multiple values in ui-grid? (angularjs)

我正在尝试制作一个过滤器,为过滤器传递多个值,但只有一个 return。

field: 'name',
    filter: {
       condition: function(searchTerm, cellValue) {
        var strippedValue = (searchTerm).split(';');
        //console.log(strippedValue);
        for (i = 0; i < strippedValue.length; i++){
          if (cellValue.indexOf(strippedValue[i]) == -1)
            return false;    
          return true;
        }
        //return cellValue.indexOf(strippedValue) >= 0;
      }
    }, headerCellClass: $scope.highlightFilteredHeader

在这里找到测试代码http://plnkr.co/edit/UVDWfucjclXl4Ij9Ylm7?p=preview

已解决,我也做了一些调整来完善代码。

 condition: function(searchTerm, cellValue) {
    var separators = ['-', '/', ':', ';', ','];
    var strippedValue = searchTerm.split(new RegExp(separators.join('|'), 'g'));
    var bReturnValue = false;
    //console.log(strippedValue, "teste");
    for(iIndex in strippedValue){
        var sValueToTest = strippedValue[iIndex];
        sValueToTest = sValueToTest.replace(" ", "");
        if (cellValue.toLowerCase().indexOf(sValueToTest.toLowerCase()) >= 0)
            bReturnValue = true;
    }
    return bReturnValue;
}

查看 link 中的代码: http://plnkr.co/edit/UVDWfucjclXl4Ij9Ylm7?p=preview

如果有人需要 AND 而不是 OR

filter: {
         condition:function(searchTerm, cellValue){          
                    if(cellValue===null){
                        return false;
                    }
                    let separators = [' ', '/', ':', ';', ','];
                    let strippedValue = searchTerm.split(new RegExp(separators.join('|'), 'g'));
                    let bReturnValue = false; 
                    let intNumFound = 0;
                    for(let iIndex in strippedValue){
                            let sValueToTest = strippedValue[iIndex];
                            sValueToTest = sValueToTest.replace(" ", "");
                            if (cellValue.toLowerCase().indexOf(sValueToTest.toLowerCase()) >= 0){
                            intNumFound++;
                            }
                            //bReturnValue = true;
                    } 
                    if(intNumFound>=strippedValue.length){
                        bReturnValue = true;
                    }
                    return bReturnValue;   
                }