Passing variable to other JavaScript file
I have a TableView loaded from a SQLite db, and by tapping an item (iPhone) the users goes to another js document with content.
At this moment I load the content by querying the database with the window's title:
var rows = db.execute('SELECT info FROM MYTABLE
WHERE name = "' + Titanium.UI.currentWindow.title + '" ');
Of course, this is not an ideal method. My question is therefore: how can I pass a parameter (like id) from the TableView data to the other JavaScript file?
Thanks!
Pieter
3 Answers
-
Accepted Answer
Hi
Just use this code:
var newWindow = Titanium.UI.createWindow({ title:'whatever', url: "details.js", info: "you informations for the new window" });
To recieve the parameter use:
var win = Titanium.UI.currentWindow; alert(win.info);
Felix
-
Thanks! That works very well if I enter the content for info directly. One issue left: I retrieve data from a SQLite db and load them in a TableView.
See here on Pastie for some code. As you see, I have been playing around a little.
Question: how can I retrieve the content for info directly from the db? I cannot use e.index (no correlation with db), and I seemingly cannot add it to the data-array (iPhone simulator crashed in that case).
The data for "info" are in rows.field(2) in the database. Hope that my explanation makes sense this way….
-
It would even be easier to use a global variable; e.g:
Set a Global Variable first like this for a string: Ti.App.Properties.setString("NameAvariable","value");
then output your variable in any js file you have like this: Ti.App.Properties.getString("yourVariableName");
and at any time you can assign any value to your global variable.