2017-04-13 2 views
0

왜이 오류가 발생 하나, 이미 내 클래스에서 생성자를 추가합니다. android-run start를 실행하고이 오류가 발생하면 오류가 나타납니다.null이 (this.state.noteArray를 평가하는) 객체가 아닙니다. - React Native

는 null ('this.state.noteArray을'평가) 객체가 아닌

export default class testPoject extends Component { 
constructor(props) { 
    super(props); 
    this.state = {noteArray: []} 
} 

render() { 

    let notes = this.state.noteArray.map((val, key) => { 
     return <Note key={key} keyval={key} val={val} deleteMethod={() => this.deleteNote(key)} /> 
    }); 

    return (
    <View style={styles.container}> 

      <View style={styles.header}> 
       <Text style={styles.headerText}>TODO LIST </Text> 
      </View> 

      <ScrollView style={styles.scrollConainer}> 

      </ScrollView> 

      <View style={styles.footer}> 

       <TouchableOpacity style={styles.addButton}> 
        <Text style={styles.addButtonText}> 
         + 
        </Text> 
       </TouchableOpacity> 

       <TextInput style={styles.noteInputText} 
        placeholder="> Note" 
        placeholderTextColor="#FFF" 
        underlineColorAndroid="transparent" 
        numberOfLines = {3} 
       /> 

      </View> 

    </View> 
    ); 
} 

}

답변

0

왜 당신이 당신의지도 함수에 발 및 키를 전달하는? noteArray는 키이고 값 쌍이있는 객체가 아니라 배열입니다. 이더 노트로 noteArray를 작성하십시오 : noteArray : {} 또는 단일 요소로 작동하도록 맵 함수를 변경하십시오.

1

음, 한 가지만하면됩니다. 생성자를 추가하고 해당 생성자에서 상태를 선언하십시오.

constructor() { 
super(); 
this.state = { 
    noteArray:[{ 'note': 'Bingo'}], 
    noteText:'', 
} 

}

관련 문제