2017-08-24 15 views
0

リゾルバを使用して、提供されたIDと一致するモデルデータをすべてデータベースから取得しています。 だから、私は私= 140 detailIdが、それは項目が 0: {detailId: 140, area: 4, depth: 1, complete: false} 1: {detailId: 140, area: 5, depth: 4, complete: false} 2: {detailId: 140, area: 6, depth: 8, complete: false} 3: {detailId: 140, area: 7, depth: 10, complete: false} 4: {detailId: 140, area: 8, depth: 3, complete: false} 5: {detailId: 140, area: 9, depth: 3, complete: false}リゾルバデータから特定のインデックスから情報を取得する

すなわちdetailId

私は深度値を取得したいことがある配列内のすべての結果を返すモデルデータのすべてを与えると言います:

(私は何とか関数にインデックス/面積値を渡す考えていた各特定領域に対してI動的よう(上の4 = index4ので、これらの目的のために、領域)のようformBuilder介して値を割り当てることができるようにそこで計算されますか?)

this.detailForm = new FormBuilder().group({ 
     index4: [this.getDepth(4)], 
     index5: [this.getDepth(5)], 
     index6: [this.getDepth(6)] 
    }); 

と機能のために、この線に沿って何かを持つ:

getDepth(index: number) { 
    // return depth value where area == index 
} 

どのように私はこの作業を行うことができますか?

+0

index4:[this.resultArray [0] .depth] – Vega

+0

@Vega編集:用事でインデックスインスタンスがあります指定された領域の値がnullの場合、ロードされないため、以降のエントリのインデックスが壊れるため、変更されます。 – CodyCS

答えて

0

私はそれを考え出しました:その後、

index4: [this.getDetailAreaDepthByIndex(4)] 

getDetailAreaDepthByIndex(index: number): number { 
    if (!this.detailArea) 
     return null; 

    let filteredItems = this.detailArea.filter(i => i.area === index) || []; 

    return filteredItems.length > 0 ? filteredItems[0].depth : null; 
} 
関連する問題