Issue
I am creating a ticket scanner app with expo React Native.
When I scan a qr code I have a var called ScannedCode.
When I render the jsonData in the app the output is:
{"txid":"ch_3LZwATA4WCavBwXA1iN5diTN"}{"txid":"ch_3LZwBNA4WCavBwXA0kPBItB3"}{"txid":"ch_3LZwEkA4WCavBwXA02WfrvTP"}{"txid":"ch_3LZwFMA4WCavBwXA0xaSxBTv"}
I use an if statement to check if the ticket (txid) is valid. So I want it to be something like this:
if (ScannedCode === jsonData) {Ticket is valid} else {not valid] My problem is the if statment dont check each json data.
I want it to check if "one of the" json txid exist {ticket is valid}
In my code below I believe the IF statement check if the scanned code is equal to the total json data. Because in the screenshot of the app, I scanned a code that existed in the jsonData, but the output was a red button that said not valid. It should be green and say valid.
Any suggestion?
var TicketStatus= "No status"
var StatusColor = "#000000"
var ScannedCode = ScannedWithCamera;
//var jsonData= "ch_3LZwFMA4WCavBwXA0xaSxBTv";
var jsonData = data.map((txid) => {
return (
JSON.stringify({ ...txid})
)
})
if (ScannedCode === jsonData) {
TicketStatus = "VALID"
StatusColor = "green"
} else if (ScannedCode === "") {
TicketStatus = ""
} else {
TicketStatus = "NOT VALID"
StatusColor = "RED"
}
Solution
Solved it like this:
if (data.some(function(e){ return e.txid=== ScannedCode})) {
BillettStatus = "GYLDIG"
StatusColor = "#008000"
} else if (ScannedCode === "") {
BillettStatus = ""
} else {
BillettStatus = "IKKE GYLDIG"
StatusColor = "#FF0000"
}
Answered By - Soreng


0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.