仅过滤 2 列中的 3 列 AngularJS


<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>

我有这张桌子。我怎样才能使过滤器仅适用于描述长或描述短,而不是在主键中。此时,过滤器仅适用于描述长。 数据场景

我想这就是你想要的:

<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;
  });
}

普鲁纳:http://plnkr.co/edit/VMcs064WWbGraULyXQTU?p=preview尝试按 01 搜索 - 不显示任何内容,它不是按主键搜索。

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

为什么不使用多个过滤器?

最新更新