programing

getter에서 Vue 체인 여러 필터

bestcode 2022. 8. 11. 23:01
반응형

getter에서 Vue 체인 여러 필터

Getter에서는 배열을 필터링하여 2개의 조건에 일치하는 값을 반환해야 합니다.현재 위치와 동일한 item_category_location이 없거나 item_category_locations가 전혀 없는 item_category를 반환해야 합니다.

 unaddedItemCategories(state, getters, rootState) {
                let otherLocations = state.item_categories
                    .filter((item_category) =>
                        item_category.item_category_locations.some((item_category_location) => item_category_location.location_id !== rootState.currentLocation.id))
                let noLocations = state.item_categories
                    .filter(item_category => item_category.item_category_locations.length == 0)
                return otherLocations, noLocations

            },

2개의 필터는 정상적으로 동작.새로운 어레이를 작성하려면 어떻게 해야 합니까?

다음과 같이 할 수 있습니다.

return [...otherLocations, ...noLocations]

언급URL : https://stackoverflow.com/questions/59609475/vue-chain-multiple-filters-in-getter

반응형