Load Data for TableView from JSON (Saved in File)
If a user is offline, I'd like to load tableview data from a cached file (saved to the filesystem the last time the user was online and fetched the data via XHR).
I use an array of rows (each row has 3 labels) as the data for the tableview. How can I serialize this array to a string, store it in a file, and later pull it out and use it to populate the data for a tableview?
This does not work:
//Save to file
var json = JSON.stringify(arrayTableData);
var fileName = 'test.json';
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, fileName);
file.write(json);
//Load from file
var fileName = 'test.json';
var file = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory, fileName);
if (file.exists()) {
var json = file.read();
tableView.setData(JSON.parse(json));
}
1 Answer
-
Hi Slim McKinsley,
I'd love to know how is the possibility of your question :)
You want share your piece of that code please?Thanks a lot!!!