반응형
null의 '포함' 속성을 읽을 수 없습니다.
JavaScript에서 Vue.js를 사용하고 있습니다.
다음 오브젝트 배열이러한오브젝트 배열이 있습니다.products
그리고 모든 물체는property
불렀다smallest_unit_barcode
다음과 같은 바코드로 제품만 필터링하고 싶다.value
그래서 다음 기능을 수행했습니다.
if (value != '') {
var results = this.products.filter(obj=>obj.smallest_unit_barcode.includes(value));
var results = results.slice(Math.max(results.length - 20, 0))
this.pos_quick_lunch = results;
}
모든 것이 잘 작동하지만obj.smallest_unit_barcode == null
, 다음의 에러가 표시됩니다.
Error in v-on handler: "TypeError: Cannot read property 'includes' of null"
내가 어떻게 무시하지?null
제품 어레이를 필터링할 때 어떤 값을 얻을 수 있습니까?
비교null
속성에 액세스하기 전에 다음을 수행합니다.
obj => obj.smallest_unit_barcode !== null && obj.smallest_unit_barcode.includes(value)
왜냐면&&
단락 중. 왼쪽 피연산자가 false로 평가되면 오른쪽 피연산자가 평가되지 않습니다.
언급URL : https://stackoverflow.com/questions/62714171/cannot-read-property-includes-of-null
반응형
'programing' 카테고리의 다른 글
자바 클래스 파일 형식의 메이저버전 번호 목록 (0) | 2022.06.29 |
---|---|
Vue 라우터 킵얼라이브가 작동하지 않음 (0) | 2022.06.29 |
이벤트 VueJs의 소품 컴포넌트 (0) | 2022.06.29 |
Selenium WebDriver를 사용하여 요소가 존재하는지 테스트합니다. (0) | 2022.06.29 |
Quasar와 함께 성분 저장 사용 (0) | 2022.06.29 |