나는 category select
드롭 다운을 가지고 있으며 현재이 배열에서 가상 데이터를 사용하고 있습니다.ReactJS - onChange 이벤트를 사용하여 매핑 할 수 없습니다.
constructor() {
super();
this.state = {
search: '',
categories: '',
products: '',
categories: ['Technology', 'Sport', 'Fashion', 'Clothes'],
}
그런 다음, 나는 그것을
<div className="col-lg-4">
<select id="categories" className="form-control">
{
this.state.categories.map((i, index) => <option key={index} value={i} >{i}</option>)
}
</select>
</div>
을 통해 작동이 방법을 반복 매핑을 사용합니다. 그러나, 나는 선택한 카테고리에 따라 상태를 변경하려면,하지만 난 select
에 onChange={handleCategories}
를 추가 할 때 오류 얻을 : (I 객체로 매핑을 사용하는 동안 사람들이 일반적으로 문제가 눈치 만의 작품을 인터넷 검색을하여
Uncaught TypeError: this.state.categories.map is not a function
을 배열에 대한), 그러나 내 문제에 대한 링크를 찾을 수 없습니다.
작동하지 :
<div className="col-lg-4">
<select id="categories" onChange={handleCategories} className="form-control">
{
this.state.categories.map((i, index) => <option key={index} >{i}</option>)
}
</select>
</div>
업데이트 코드로 질문을 알 수 없습니다 일. 'onChange' 함수는 어떻게 전달합니까? –
@Prakash 업데이트 – Seinfeld
옵션을 변경하면 오류가 발생합니까? 그렇다면'handleCategories' 함수를 보여줍니다. –