![](/img/trans.png)
[英]How to pass a function to a react native custom component but not run until onPress
[英]How to pass params to function on onPress in react native
我是新來的反應本地人。 我想將leadTagNumber傳遞給function,然后傳遞給API。 那么如何將該leadTagNumber傳遞給function。 請幫忙。
這是我的代碼
ScreenData () {
const {navigation} = this.props
const data = this.props.route.params.data
const leadTagNumber = this.props.route.params.leadTagNumber
AsyncStorage.multiGet(["application_id", "created_by"]).then(response => {
console.log(response[0][1]) // Value1
console.log(response[1][1]) // Value2
console.log(leadTagNumber)
fetch("https://nasdigital.tech/Android_API_CI/get_merchant_onboard_data", {
method: "POST",
headers: { 'Accept': 'application/json, text/plain, */*', "Content-Type": "application/json" },
body: JSON.stringify([{ id:response[1][1], application_id:response[0][1], lead_tag_number:leadTagNumber}]),
})
.then((returnValue) => returnValue.json())
.then((response) => {
alert(JSON.stringify(response))
console.log(response)
{
this.props.navigation.navigate("FormItems", {
});
}
})
.catch((error) => console.log(error));
})
render() {
const data = this.props.route.params.data
{data.map(item =>
<TouchableOpacity onPress={() => this.ScreenData({leadTagNumber:item.lead_tag_number })}>
<Card center middle shadow style={{ height:80, width:"100%" }} >
<Text medium height={15} size={14}style={{ paddingRight:190, width:'200%'}}>
{item.lead_tag_number}
</Text>
</Card>
</TouchableOpacity>)}
請忽略這個=我是新來的反應原生的。 我想將leadTagNumber傳遞給function,然后傳遞給API。 那么如何將該leadTagNumber傳遞給function。 請幫忙。
ScreenData(leadTagNumber){
console.log(leadTagNumber)
}
<TouchableOpacity onPress={() => this.ScreenData(item.lead_tag_number)}>
</TouchableOpacity>
將參數傳遞給 function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.