2017-04-13 77 views
0

爲什麼即時通訊接收到這個錯誤,但我已經添加了我的類的構造函數。 錯誤只是出現在我執行Android運行開始和即時通訊獲取此錯誤。null不是一個對象(評估'this.state.noteArray') - 反應原生

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

你爲什麼要傳遞一個VAL和關鍵是你的地圖功能? noteArray是一個數組,不是具有鍵值對的對象。 Ether將noteArray寫成noteArray:{}或更改地圖函數以使用單個元素。

1

那麼, 做一件事情,它會工作。添加一個構造函數並在該構造函數中聲明該狀態。

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

}

相關問題