반응형
이 두 어레이를 연결할 수 없는 이유는 무엇입니까?
코드(Vuex 변환)는 다음과 같습니다.
export const CREATE_PANORAMAS = (state, panoramas) => {
console.log('building.panoramas:', state.building.panoramas)
console.log('panoramas:', panoramas)
state.building.panoramas.concat(panoramas)
console.log('result:', state.building.panoramas)
}
그 결과, 다음의 각 로그가 표시됩니다.
[] // building.panoramas
[{ name: "", objectId: "5849133aac502e006c581b58" }] // panoramas
[] // result
두 어레이가 연결되지 않는 이유는 무엇입니까?
From documentation - concat() 메서드는 두 개 이상의 어레이를 Marge하기 위해 사용됩니다.이 메서드는 기존 어레이를 변경하지 않고 새 어레이를 반환합니다.
concat를 사용하는 한 가지 방법은 다음과 같습니다.
state.building.panoramas = state.building.panoramas.concat(panoramas)
아니면 간단하게
[].push.apply(state.building.panoramas, panoramas);
문제는 연결 결과를 에 할당하지 않는다는 것입니다.state.building.panoramas
@JaromandaX에 의해 나타나는 배열입니다.
또한 rest 요소, 확산 요소, 할당 파괴 기능을 사용하여 두 개 이상의 어레이를 연결할 수도 있습니다.
[...state.building.panoramas] = [...state.building.panoramas, ...panoramas];
주(州)를 정해야 할 것 같아요building.sublicamas.concat(비밀번호)를 먼저 지정하거나 '결과' 행에 직접 추가할 수 있습니다.
sampleArray.concat(moreValues)는 연결된 배열을 반환하며 'moreValues'를 sampleArray 자체에 연결하지 않습니다.
언급URL : https://stackoverflow.com/questions/41034619/why-cant-i-concatenate-these-two-arrays
반응형
'programing' 카테고리의 다른 글
모든 요청에 대해 서버에서 Vue + Axios 처리 오류 발생 (0) | 2022.06.26 |
---|---|
네임슬레이드 모듈에 매핑할 때 프로펠을 모듈 이름으로 전달합니다. (0) | 2022.06.26 |
가져올 때 기호를 확인할 수 없습니다. (0) | 2022.06.25 |
Java: 인스턴스 상세 복제/복사에 권장되는 솔루션 (0) | 2022.06.25 |
C의 함수 포인터는 어떻게 작동합니까? (0) | 2022.06.25 |