2016-09-28 5 views
0

レコードの配列があり、ヘッダーにフィルタを含むHTMLテーブルで繰り返しています。いくつかの値はフィルタによって変換され、ng-repeatフィルタが失敗することが判明しました。変換フィルタを使用した検索入力に基づくng-repeat

<table class="table"> 
    <thead> 
    <tr> 
     <td><input ng-model="search.time" type="text" class="form-control" /></td> 
    </tr> 
    </thead> 
    <tbody> 
    <tr ng-repeat="record in records | filter: search"> 
     <td>{{record.time | timeFormatter}}</td> 
    </tr> 
    </tbody> 
</table> 

わかっているように、テーブル列の値はtimeFormatterフィルタによって変換されています。したがって、 "0800"ではなく、 "08:00 AM"と表示されます。ユーザーが「08」と入力すると機能しますが、「08:」または「AM」と入力するともう機能しません。

フィルタを表の列に表示されている値(書式付き)と一緒に使用できるように助けてもらえますか?

ありがとうございます。

+0

です。 –

+0

私はちょうど私が必要なものを理解するのに役立つこのcodepenを作成しました.. https://codepen.io/marcioferlan/pen/PGjxya –

答えて

0

これは単なる推測ですが、あなたのモデルはsearch.timeに変更を保存していますが、フィルタは 'フィルタリング'検索です。フィルターでsearch.timeを使用してみてください。

+0

私は実際のコードでは、ユーザがフィルタリングするために使用できるフィールド。このコードを確認してください。https://codepen.io/marcioferlan/pen/PGjxya –

1

あなたはおそらく命令で遊ぶ必要があるでしょう。これを試してみてください:

angular.module("app").directive("myDirective", function(){ 
    return { 
     require: 'ngModel', 
     link: function(scope, element, attrs, ngModelController) { 
     ngModelController.$parsers.push(function(data) { 
      //convert data from view format to model format 
      return input.substring(0, 2) + ':' + input.substring(2) 
     }); 

     ngModelController.$formatters.push(function(data) { 
      //convert data from model format to view format 
     return input.substring(0, 2) + ':' + input.substring(2) 
     }); 
     } 
    }; 
}); 

は、ここでは、timeFormatterフィルタ内のコードを表示する必要がPlunker

関連する問題