2017-01-18 7 views
0

私はあなたが私はNの結果とテーブルを持っていると私は日付の範囲のためのフィルタを実行しようとしていフィルター結果

アンギュラ材料に非常に新しいです私を助けることができると思います。私は HTML

<div layout="row" flex="90" layout-align="start center"> 
    <label flex="25">Rango</label> 
     <select flex="60" ng-model="vm.rangoSelected" placeholder="" ng-options="ran.name for ran in vm.rangos" class="selectPersonalizado "> 
     </select> 
</div> 

vm.rangos=[ 
    {id:"1",name:'1 día',value:'1'}, 
    {id:"2",name:'5 días',value:'5'}, 
    {id:"3",name:'1 Semana',value:'7'}, 
    {id:"4",name:'15 días',value:'15'} 
    ]; 

JS

変数

がロードされているオプション(1日、5日、1週間、15日)、とを選択しており、私は正直なところ、選択された範囲内の結果を表示するためのフィルタの実行方法を知らない。

この関数では、 eは私に選択の値を示し、警戒whithこの機能では

function sendFilter(){ 
     var filterSend = ""; 
     switch(vm.filterSelected){ 

      case 'rango': 
      filterSend = vm.rangoSelected.value; 
      break; 
      default: 
      alert('no hecho'); 
      break; 

     } 
     vm.showLastMovements(filterSend); 
    } 

JSON

{ 
    "result": { 
    "httpCode": 200, 
    "httpMessage": "OK", 
    "moreInformation": "" 
    }, 
    "data": { 
    "movements": [ 
     { 
     "operationDate": "2017-01-18", 
     "concept": "Decathlon", 
     "amount": "-450.0", 
     "currency": "EUR", 
     "balance": "29150.0", 
     "category": 1 
     }, 
     { 
     "operationDate": "2017-01-18", 
     "concept": "Corte Ingles", 
     "amount": "-259.0", 
     "currency": "EUR", 
     "balance": "34000.0", 
     "category": 2 
     }, 
     { 
     "operationDate": "2017-01-15", 
     "concept": "Carrefour", 
     "amount": "348.0", 
     "currency": "EUR", 
     "balance": "12000.0", 
     "category": 1 
     }, 
     { 
     "operationDate": "2017-01-01", 
     "concept": "Corte Ingles", 
     "amount": "-259.0", 
     "currency": "EUR", 
     "balance": "34000.0", 
     "category": 2 
     }, 
     { 
     "operationDate": "2016-12-30", 
     "concept": "Cortefiel", 
     "amount": "348.0", 
     "currency": "EUR", 
     "balance": "12000.0", 
     "category": 1 
     } 

    ] 
    } 
} 

を選択しました。

この機能を作成するための情報を提供したり、ケースの電話をかけてその選択肢の記録を表示したりすることができれば、私はそれを感謝します。

ありがとうございました

+0

範囲でフィルタリングしようとしているコンテンツは何ですか? –

+0

私はいくつかの結果(カテゴリ、日付、説明、価格)を持つリストを持っています。私が表示しようとするこのフィルタは、私が選択したもの(1日、5日、1週間または15日間)実際にはJSONを使ってリストを表示しています – derek

+0

私は理解しているかどうかはわかりませんが、フィルターを使用して範囲に応じて結果をフィルターしたいと思います。選択した範囲と結果コンテンツの日付を比較しますか? –

答えて

0

これはあなたのhtmlされます。

<div layout="row" flex="90" layout-align="start center"> 
    <label flex="25">Rango</label> 
     <select flex="60" ng-model="vm.rangoSelected" placeholder="" ng-options="ran.name for ran in vm.rangos" class="selectPersonalizado "> 
     </select> 
</div> 

そして、これがdata.movementsリスト

<tr md-row ng-repeat="movement in data.movements | filter: customFilter"> 
    <td md-cell>{{movement}}</td> 
    </tr> 

コントローラを通して、あなたのテーブルの繰り返しであると仮定してみましょう:

function customFilter(movement){ 
    var movementDate = new Date (movement.operationDate); 
    var filterDate= new Date(); 
    filterDate.setDate(filterDate.getDate() - vm.rangoSelected.value) //In here you will have to transform the rangoSelected.value to days. 
    return (movementDate.getTime() > filterDate.getTime()); //this will return true if the movement's date is bigger than your selected range. 
} 

getTime()は、1970/01/01以降のミリ秒数を返します。それは範囲の計算を行うのに役立ちます。

関連する問題