数组不是一个函数(评估'this.props.onPress(e)')



这是错误屏幕:错误屏幕

渲染代码中的按钮:

<View style={{flex:1}}>
<Image source={require('../images/plots2.jpg')}
style={{flex:1,height:null,width:"100%",resizeMode:'contain'}}
/>
<Button onPress = {this.abc(this.state.items)}
title="Retrive Database Table"
/>
</View>

按钮中的功能在此调用代码:

abc (items) {
console.log("IN hashir");
//console.log("Hashir RAN count: "+this.state.countrunHashir);
//var a=this.state.countrunHashir+1;
//this.setState(countrunHashir:1);
//this.state.countrunHashir+=1;
return(
items.map(item=>{
return(
<Card style={{marginLeft: 5, marginRight:5}}>
<CardItem header style={{borderBottomWidth:1,borderBottomColor:'#dee0e2'}}>
<Text style={{backgroundColor:'white',color:'red',fontSize:25,fontWeight:'bold',textAlign:'center',justifyContent:'center'}}>
Items Recommended For You
</Text>
</CardItem>
<RecommendedCardItem 
title={item.Title}
model="has"
StartingBid="hashir"
imageUri={require("../images/h1.jpg")}
rating={3}
/>
<TouchableOpacity style={{alignContent:'center', backgroundColor:'#b2ff59',width:'100%',borderRadius:25,marginVertical:10,paddingVertical:12 }}>
<Text style={{fontSize:22, fontWeight:'bold', color:'#ffffff',textAlign:'center',color:'black'}}>Click For More Details</Text>
</TouchableOpacity>
</Card>
);
})
);
}

在构造函数代码中初始化的状态:

this.state={
items:[],
mainscreenrender:0,
countrunHashir:0
};

呈现问题是当按钮想要使用数组"items"来呈现整个视图列表时。你能帮我改进一下代码吗?非常感谢你。

谢谢!

尝试为onPress属性提供回调函数,而不是"value"。你的代码应该看起来像:

<Button onPress = {() => this.abc(this.state.items)} 
title="Retrive Database Table" />

最新更新