Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native undefined不是对象(计算';this.onSubmitPressed.bind';)_React Native - Fatal编程技术网

React native undefined不是对象(计算';this.onSubmitPressed.bind';)

React native undefined不是对象(计算';this.onSubmitPressed.bind';),react-native,React Native,我有一个通过Json显示数据的列表视图。我引入了一个函数,当单击每一行时,它会显示一个警报,包括{shop_name}。 但在第一步,它并没有意识到这个功能。 函数在同一类中 当我在onPress中输入Alert时,它就起作用了 class SearchPage extends Component { constructor(props) { super(props); var dataSource = new ListView.Dat

我有一个通过Json显示数据的列表视图。我引入了一个函数,当单击每一行时,它会显示一个警报,包括{shop_name}。 但在第一步,它并没有意识到这个功能。 函数在同一类中 当我在onPress中输入Alert时,它就起作用了

 class SearchPage extends Component {

        constructor(props) {
          super(props);
          var dataSource = new ListView.DataSource({rowHasChanged:(r1,r2) => r1.ruid != r2.guid});
          this.state = {
            id: 'SearchPage',
            shopid: this.props.shopid,
            homesearchinpt: this.props.homesearchinpt,
            dataSource: dataSource.cloneWithRows(shopsArray),
            isLoading: true
          };
        }

        componentDidMount(){
          this.fetchData();
        }
        onSubmitPressed(){
          Alert.alert(
            'Alert Title',
            'alertMessage',
          )
        }
        fetchData() {
            fetch(REQUEST_URL)
                .then((response) => response.json())
                .then((responseData) => {
                    this.setState({
                    dataSource: this.state.dataSource.cloneWithRows(responseData),
                    loaded: true,
                });
            })
            .done();
        }
        render() {
            if (!this.state.loaded) {
                return this.renderLoadingView();
            }
            return (
                <ListView
                    dataSource={this.state.dataSource}
                    renderRow={this.renderShops}
                    style={styles.listView}

                />
            );
        }
        renderLoadingView() {
            return (
                <View style={styles.container}>
                    <Text>Loading</Text>
                </View>
            );
        }

        renderShops(shop) {

            return (


                <View style={styles.container} >
             <TouchableOpacity onPress={this.onSubmitPressed.bind(this)}>
                    <Image
              source={{uri: shop.shop_logo}}
              style={{width: 50, height: 50}}>
            </Image>
              <View>
                <Text style={styles.shop_name}>{shop.shop_name}</Text>
                <Text style={styles.shop_description}>{shop.shop_description}</Text>
              </View>

            </TouchableOpacity>
          </View>

            );
        }

};
类搜索页面扩展组件{
建造师(道具){
超级(道具);
var dataSource=newlistview.dataSource({rowHasChanged:(r1,r2)=>r1.ruid!=r2.guid});
此.state={
id:“搜索页面”,
shopid:this.props.shopid,
homesearchinpt:this.props.homesearchinpt,
dataSource:dataSource.cloneWithRows(shopsArray),
孤岛加载:正确
};
}
componentDidMount(){
这是fetchData();
}
onSubmitPressed(){
警惕,警惕(
“警报标题”,
“警报消息”,
)
}
fetchData(){
获取(请求URL)
.then((response)=>response.json())
.然后((响应数据)=>{
这是我的国家({
dataSource:this.state.dataSource.cloneWithRows(responseData),
是的,
});
})
.完成();
}
render(){
如果(!this.state.loaded){
返回此.renderLoadingView();
}
返回(
);
}
renderLoadingView(){
返回(
加载
);
}
渲染器(商店){
返回(
{商店。商店名称}
{shop.shop_description}
);
}
};
错误:

undefined不是对象(计算'this.onSubmitPressed.bind')


this.onSubmitPressed(shop.shop\u name)}>

我重写了代码,问题就解决了。
谢谢

即使没有shop.shop\u名称,我仍然有相同的错误。只有基本警报也有错误。它找不到函数:(考虑在构造函数中将make
bind
绑定到你的
funcs
)这对任何有相同问题的人都没有帮助。如果你已经解决了问题,你应该写下你找到的解决方案。
onSubmitPressed(shopName) {
  Alert.alert(
    'Alert Title',
    shopName,
  )
}
<TouchableOpacity onPress={() => this.onSubmitPressed(shop.shop_name)}>