2016-12-17 59 views
0

我有这个错误,找不到原因。一切似乎都很好。该代码是作为逻辑工作,但在应用程序启动事情变得有价值。无法读取属性为空的'pin' - 反应原生

import React, { Component } from 'react'; 
import { AppRegistry, StyleSheet, Text, View, MapView} from 'react-native'; 

var weather = React.createClass({ 
    getInitialstate: function(){ 
    return { 
     pin:[{ 
     longitude:33.33, 
     latitude:33.33 
     }] 
    }; 
    }, 

    render: function(){ 
    return (
     <MapView annotations={[this.state.pin]} style={styles.map} onRegionChangeComplete={this.onRegionChangeComplete}> 
     </MapView> 
    ) 
    }, 

    onRegionChangeComplete: function(region){ 
    this.setState({ 
     pin:{ 
     longitude: region.longitude, 
     latitude: region.latitude 
     } 
    }); 

    // console.log([this.pin]); 
    } 

}); 

var styles = StyleSheet.create({ 
    map:{ 
    flex:1 
    } 
}) 

AppRegistry.registerComponent('weather',() => weather); 

我使用mapView和更改注释。请帮忙 !

+3

的构造函数的状态对象你有几个错误,但我想这涉及这个问题之一是,你定义'getInitialstate'不'getInitialState'。 –

回答

0

创建耐候级

constructor(props){ 
    super(props); 
    this.state = {}; 
} 
+0

这仅适用于ES6类。正如你所看到的,他正在使用createClass。 –