2017-09-21 1 views
0

私はdata.iの配列を持つjsonオブジェクトを別の配列でフィルタリングしたいのですが。typescript配列のフィルタリングが機能しない

MY .tsファイルは次のとおりです。ここで

let filter_bank_id=[4,25,6,1]; 
     console.log(filter_bank_id.length); 

     if(data.offers){ 
      let last =data.offers.filter(offer=>{ 
       for(let i=0;i<filter_bank_id.length;i++){ 
        if(data.offers[i]){ 
        let bank=filter_bank_id[i]; 
         if(bank){ 
         if(bank===data.offers[i].bank_id){ 
          return offer; 
         } 
         } 
        }else{ 
        alert("nodata"); 
        } 
       } 
      }); 
      console.log(last); 
     } 

は提供しています複数のdata.iを持つJSONオブジェクトがfilter_bank_id array.Thatでそれをフィルタリングしたいされて、私はそれがあるarray.Butのみfilter_bank_idのようbank_id 4,25,6,1で提供していますしたいこと働いていない。 問題は、私はそれがit.Myに入っていないデバッガを与えるこのline.whenは、JSONオブジェクトは以下の通りです提供しています "オファーが> =(前回= data.offers.filterをしましょう" とある

offers= [ 
    { 
     "image": "assets\/banks\/axi1419231043.jpg", 
     "offerid": 1, 
     "id": "1", 
     "bank_id": "1", 
     "name": "AXIS BANK", 
     "bank_interest": "10.99", 
     "emi": "2,174", 
     "processing_fee": "990", 
     "precloser_cost": "0 %", 
     "part_pay": "Yes", 
     "insurance": null, 
     "conditions": "", 
     "intrest_1_year": 0, 
     "intrest_total": 0 
    }, 
    { 
     "image": "assets\/banks\/hdfc1418896652.png", 
     "offerid": 7, 
     "id": "4", 
     "bank_id": "4", 
     "name": "HDFC BANK", 
     "bank_interest": "10.99", 
     "emi": "2,174", 
     "processing_fee": "500", 
     "precloser_cost": "4.49 % for 12-24 months,3.37 % for 24-36 months,2.25 % for 36-60 months,", 
     "part_pay": "Yes", 
     "insurance": "1,362", 
     "conditions": "", 
     "intrest_1_year": 0, 
     "intrest_total": 0 
    }, 
    { 
     "image": "assets\/banks\/scb1438520764.png", 
     "offerid": 2, 
     "id": "16", 
     "bank_id": "16", 
     "name": "SCB", 
     "bank_interest": "11.00", 
     "emi": "2,175", 
     "processing_fee": "1000", 
     "precloser_cost": "0 %", 
     "part_pay": "Yes", 
     "insurance": null, 
     "conditions": "", 
     "intrest_1_year": 0, 
     "intrest_total": 0 
    }, 
    { 
     "image": "assets\/banks\/citi1419219218.png", 
     "offerid": 3, 
     "id": "2", 
     "bank_id": "2", 
     "name": "CITI BANK", 
     "bank_interest": "11.49", 
     "emi": "2,199", 
     "processing_fee": "2999", 
     "precloser_cost": "2 %", 
     "part_pay": "Yes", 
     "insurance": null, 
     "conditions": "", 
     "intrest_1_year": 0, 
     "intrest_total": 0 
    }, 

];。

事前に私のfilter.pleaseヘルプme.Thankに問題がどのようなものです。この

offers.filter((offer) => filter_bank_ids.indexOf(offer.bank_id) > -1)

Aのような

+0

あなたのコードをplunkrまたはjsfiddleに置くことができますか? –

答えて

0

使用フィルタこのスニペットを使用する前に、あなたのタイプをチェックしてください。これがあなたを助けることを願っています

+0

それはまた動作していません。問題はそのフィルタで解決されていません。 – Pranav

+0

あなたのコンソールに入るエラーを投稿しますか? @Pranav – bhanu

関連する問題