PhoneGap :Retrieve the next data from table By increment sessionStorage
-
27-06-2021 - |
Pregunta
I have a ID (1) of a record in the database and each time when I click the "NEXT" button, I wish to increment the ID into 2 and retrieve the next data. I store the ID into the sessionStorage.ID and later when I retrieve it and
sessionStorage.ID =sessionStorage.ID +1
The sessionStorage should be equal to 2 but it display as "11". How can I resolve this?
Solución
Try this:
sessionStorage.ID = parseInt(sessionStorage.ID) + 1;
When you store the ID in sessionStorage, it gets saved as a string, so the +
sign concatenates the number instead of adding it.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow