2016-10-14 8 views
0
<table> 
    <tr> 
     <th>Primary Key</th> 
     <th>descriptionShort</th> 
     <th>descriptionLong</th> 
</tr> 
<tr ng-repeat="terReason in data | filter :({descriptionLong:searchTerm}||{descriptionShort:searchTerm} )"> 
     <td>terReason.primaryKey</td> 
     <td>terReason.descriptionShort</td> 
     <td>terReason.descriptionLong</td> 
</tr> 
</table> 

私はこのテーブルを持っています。どのようにフィルタは、descriptionLongまたはdescriptionShortでのみ動作し、primaryKeyでは動作しません。 この時点でフィルタはdescriptionLongでのみ動作します。 DATA sceernshotフィルターは3列のうちの2列だけです。

+0

あなたは[this](http://stackoverflow.com/a/18792135/4045532)を見ましたか? – Corporalis

+0

はい、私はそれを見ました。私はsearchTermで両方の列を検索したいと忘れていました。 searchTerm1またはsearchTerm2では使用できません。 –

答えて

1

私は、これはあなたが望むものであると仮定します

<input ng-model="searchTerm"> 
<table> 
    <tr> 
     <th>Primary Key</th> 
     <th>descriptionShort</th> 
     <th>descriptionLong</th> 
    </tr> 
    <tr ng-repeat="terReason in data | filter : myFilter"> 
     <td>{{ terReason.primaryKey }}</td> 
     <td>{{ terReason.descriptionShort }}</td> 
     <td>{{ terReason.descriptionLong }}</td> 
    </tr> 
</table> 

JS:

$scope.data = [ 
{ 
    primaryKey: 0, 
    descriptionShort: 'descriptionShort ZERO', 
    descriptionLong: 'descriptionLong descriptionLong descriptionLong ZERO' 
}, 
{ 
    primaryKey: 1, 
    descriptionShort: 'descriptionShort ONE', 
    descriptionLong: 'descriptionLong descriptionLong descriptionLong ONE' 
}, 
{ 
    primaryKey: 2, 
    descriptionShort: 'descriptionShort TWO', 
    descriptionLong: 'descriptionLong descriptionLong descriptionLong TWO' 
}, 
{ 
    primaryKey: 3, 
    descriptionShort: 'descriptionShort THREE', 
    descriptionLong: 'descriptionLong descriptionLong descriptionLong THREE' 
} 
]; 

$scope.myFilter = function myFilter (value) { 
    return !$scope.searchTerm || Object.keys(value).some(function (key) { 
    return key !== 'primaryKey' && value[key].search($scope.searchTerm) !== -1; 
    }); 
} 

pluner:http://plnkr.co/edit/VMcs064WWbGraULyXQTU?p=preview はまたはで検索してみません - 表示何も、それを主キーで検索していません。

+0

あなたの答えをありがとう。何百万というデータのすべてのプライマリキーに対してこれを行う必要がある場合は、これを多くのコードすることになります。 –

+0

あなたの答えに従うとdescriptionLongでのみ検索します。descriptionShortではありません –

+0

私は30分ほどで答えを更新します(今は残す必要があります)、指摘のために@EndritDemajに感謝します。私はprimaryKeyキーその検索から – Andriy

0
<tr ng-repeat="terReason in data | filter :filter1 | filter :filter2 "> 
     <td>terReason.primaryKey</td> 
     <td>terReason.descriptionShort</td> 
     <td>terReason.descriptionLong</td> 
</tr> 

なぜ複数のフィルタを使用しないのですか?

+0

この方法は* ORED * – Andriy

関連する問題