0
필자는 필터가 일치하는 배열을 반환해야하는 함수가 있습니다.JavaScript의 객체 배열과 다른 배열을 효율적으로 비교하는 방법은 무엇입니까?
가filter_getCustomFilterItems(filterNameToSearch: string, appliedFilters: Array<any>) {
let tempFilterArray = [];
let masterFilterList = getMasterFilterList();
/*
filterNameToSearch can be a string either as `Item2` or `Item3`
masterFilterList will be of type
masterFilterList: Array<any> = [
{
Item1: 'some-item-1',
Item2: 'some-item-2',
Item3: 'some-item-3',
Item4: 'some-item-5',
},
{
Item1: 'some-item-10',
Item2: 'some-item-11',
Item3: 'some-item-12',
Item4: 'some-item-13',
},......
];
appliedFilters will be of type
appliedFilters: Array<any> = [
{
name: 'Item1',
filters: [
{value: 'some-item-1', status: 'selected'},
{value: 'some-item-10', status: 'selected'}
]
},......
];
*/
for (let masterFilterItem of masterFilterList) {
//Missing logic here
}
}
I는 다음과 같은 조건 하에서 항목 filterNameToSearch = 'Item2'
의 배열을 반환 할 masterFilterList
필터링하고자 : 여기서 함수 코드의
1) 각각의 배열 요소 (appliedFilterItem
가정) appliedFilters
에이 비교 masterFilterItem[appliedFilterItem.name]
와 appliedFilterItem.name
및 appliedFilterItem
의 필터 중 masterFilterItem[appliedFilterItem.name]
2와 동일한 값을 가지면 조건 0,123,274,689 같은 모습한다) 확인. 그러나 appliedFilters
의 요소 수는 동적입니다.
이 문제로 나를 도와주십시오.
출력이 –
이 될지 확실하지 않습니다. 출력은 조건이 적용된 'masterFilterList'에있는 항목의 배열입니다. filterNameToSearch = "Item2"가 주어지면'appliedFilters'의 조건을 가진'masterFilters'의 모든 Item2 요소를 반환해야합니다 – starlight