我很努力讓我的頭在如何基於使用角管的另一個對象數組過濾對象數組。到目前爲止,我所擁有的是一種基於單一參數進行過濾的管道。Angular2過濾基於使用管道的對象數組的對象數組
我有2個數組,array1和數組2,它們都包含複雜的對象。將過濾的陣列(數組1)應該只包含對象,其中array1.value === array2.value
到目前爲止我的代碼:
import { Injectable, Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'arrayFilter'
})
@Injectable()
export class AttributeFilterPipe implements PipeTransform {
transform(array: any[], filterFrom: any[]): any {
return array.filter(item => item.value.indexOf(filterFrom[0].value) !== -1);
}
}
將過濾的陣列(ARR ay1)應該只包含對象,其中array1.value === array2.value - 比較同一索引處的對象?或array1應該只包含數組2中的對象? – tymeJV
array1應該只包含array2中的對象。比較應該在array1 [i] .value === array2 [i] .value –