Cordova – PhoneGap – Passing JS data between the page

I have a question about passing data between pages of a JQM/Phonegap application.

If I have a JS object that contains Some data: search terms, location and some other filter values, for example, the user jumps from the search page to the settings page, and then back to the search page… How can I save the information, what do I have in the preview page? Is there something like cookies, or should I use sqlite to save information and read it every time the user enters the search page?

I will use LocalStorage, which is quite simple to use. It allows you to store plain text:

// Writing'something' in localStorage.myvariable
localStorage.myvariable ='something'

// Displaying the previous variable< br />console.log(localStorage.myvariable)

If the plain text is not enough and you need to store the data structure, you can achieve the following:

Storage .prototype.setObject = function(key, value) {this.setItem(key, JSON.stringify(value)); }
Storage.prototype.getObject = function(key) {var value = this.getItem(key );return value && JSON.parse(value); }

// Storing a JSON object
localStorage.setObject('myObject', {key1:'value', key2:'value2 '});

// Accessing the object
localStorage.getObject('myObject')

I have a The problem of passing data between pages of JQM/Phonegap application.

If I have a JS object, which contains some data: search term, location and some other filter values, such as user search from The page jumps to the settings page, and then back to the search page… How can I save the information, what do I have in the preview page? Is there something like cookies, or should I use sqlite to save information and read it every time the user enters the search page?

I will use LocalStorage, which is quite simple to use. It allows you to store plain text:

< pre>// Writing’something’ in localStorage.myvariable
localStorage.myvariable =’something’

// Displaying the previous variable
console.log(localStorage.myvariable)< /pre>

If the plain text is not enough and you need to store the data structure, you can achieve the following:

Storage.prototype.setObject = function(key, value) { this.setItem(key, JSON.stringify(value)); }
Storage.prototype.getObject = function(key) {var value = this.getItem(key);return value && JSON.parse(value); }

// Storing a JSON object
localStorage.setObject('myObject', {key1:'value', key2:'value2'});

// Accessing the object
localStorage.getObject('myObject')

Leave a Comment

Your email address will not be published.