我有如下情况,在收到确认在 sendacknowledgement 功能中成功时,我想禁用按钮任何想法请帮助....//在 ack 响应中的代码中:是成功然后禁用//或如果它进入gotourl() 然后禁用
function gotourl() {
console.log("url===> ", url);
if (url != null) {
console.log("url===> ", url);
Linking.openURL(url);
}
acknowledgement = JSON.stringify({
ack: {
UserId: userid,
EventId: messageid,
EventName: event,
EventStatus: "Accepted",
},
});
sendack();
}
const deleteItem = (index) => {
acknowledgement = JSON.stringify({
ack: {
UserId: userid,
EventId: messageid,
EventName: event,
EventStatus: "Rejected",
},
});
sendack();
};
function sendack() {
fetch("url")
.then((response) => response.json())
.then((data) => {
sendacknowledgement(data);
});
}
function sendacknowledgement(beatoken) {
console.log("inside send ack token ====>>>>", beatoken);
console.log("acknowledgement===>", acknowledgement);
fetch("url", {
method: "PUT",
withCredentials: true,
credentials: "include",
headers: {
Authorization: "Bearer " + beatoken,
"Content-Type": "application/json",
},
body: acknowledgement,
})
.then((response) => response.json())
.then((data) => console.log("ACK Response: ", data))
.catch((err) =>
console.log("ERROR DURING SENDING ACKNOWLEDGEMENT ===> ", err)
);
}
return (
<View style={styles.container}>
{view.length <= 3 ? (
<>
<Text style={styles.heading}>NO NEW MESSAGES</Text>
</>
) : (
<>
<Text style={styles.textStyle}>{data}</Text>
<Button
onPress={() => gotourl()}
title="Accept"
color="green"
/>
<Button
onPress={() => deleteItem()}
title="Delete"
color="red"
/>
</>
)}
</View>
);
};