Passing Data Between Window?.
I want send data to one window from other. The main window has a table view. while clicking on the table view, I want to pass corresponding id to next window. The window is in other .js file. Presently, I am passing data by dispatching a custom event. But first time it doesn't work. Please help me.
tableView.js code..
var tableView=Titanium.UI.createTableView({data:data});
var nav = Titanium.UI.iPhone.createNavigationGroup({
window: win1
});
var showWin = Titanium.UI.createWindow({
url:"files/showPaper.js",
title:'Info'
});
tableView.addEventListener('click', function(e)
{
Titanium.API.info("sdfsdfsdF"+e.rowData.val);
Titanium.API.info("hjhjhjhjhjhjhjhjh");
//showWin.fireEvent('createTable',{id:e.rowData.val});
nav.open(showWin,{animated:true});
showWin.fireEvent('createTable',{id:e.rowData.val});
});
win1.add(tableView);
mainWin.add(nav);
showWin.js
var showWin=Titanium.UI.currentWindow;
//showWin.title= "jkjkjkjk";
Titanium.API.info("in Show Creation");
var itemId;
showWin.addEventListener('createTable',function(e)
{
Titanium.API.info("in Show Event");
itemId=e.id;
createTable();
});
I think, first time the eventListener not Registered.
2 Answers
-
Accepted Answer
What I do instead of firing an event, is first create the new window, then add a custom property to it with the value I want, then open that window. In the new window, I just reference that property to find the value.
tableView.addEventListener('click', function(e) { Titanium.API.info("sdfsdfsdF"+e.rowData.val); showWin.myID = e.rowData.val; nav.open(showWin,{animated:true}); } in showWin.js: Ti.API.info('myID = ' + showWin.myID);
Personally, I wouldn't bother to create the showWin window until inside the table event listener. But I was trying to keep it as close to your code as possible.
-
This is how I would do it:
Here is a simple example on how to pass and retrieve data between windows, I do the following:
var win1 = Titanium.UI.createWindow({ title: 'My Main Window', backgroundImage: 'images/bg.png', MyID: e.rowData.val }); win1.open(); // On Win1 you do the following to retrieve // Declare your current window var win = Ti.UI.currentWindow; //RETRIEVING PARAMETERS FROM PREVIOUS WINDOW var MyID = win.MyID;
This way you are passing to the next window the variable MyID.
Hope it helped.