I'm trying to pass data from a main window when a button is pressed on that page using require()
, like so:
mapview.addEventListener('click', function(evt) {
var detailWindow = Ti.UI.createWindow({
backgroundColor: '#333333',
navTintColor: '#FFF',
barColor: '#222222',
itemID: evt.annotation.myid
});
Ti.API.info('detailWindow.itemID = ' + detailWindow.itemID);
// displays expected value from database eg 12345
detailWindow = require('ui/iphone/detail');
var detailWin = new myWindowHere(detailWindow.itemID);
}
In detail.js:
function myWindowHere(myItemID) {
var myDetailsWin = Titanium.UI.createWindow({
//properties here
});
Ti.API.info('myItemID = ' + myItemID); // this log is never
var facilityID = myItemID;
myWindowHere.open();
return myDetailsWin;
};
module.exports = myWindowHere;
But, I've gone wrong somewhere as I'm getting error message: Can't find variable: myItemID
Please help! Many thanks
detailWindow
and override that variable with therequire
statement. Inside that you create a new window, why shouldmyItemID
be visible in there? Add methods to your module (e.g.myDetailsWin.passParameter = function(){}
to pass in variables or add them to the require statement as a 2nd parameter – miganew myWindowHere(detailWindow.itemID);
doesn't do anything, because the context doesn't know that object.myWindowHere.open();
doesn't point to anything either. And as @miga said you're overriding an object and expect the original to still exist... that doesn't work like that. – Rene Pot