TableView w/ Event Listener Question
I am having trouble getting the correct event listener code to correspond with my data below. I am using two different types, [test & url]. Any suggestions would be much appreciated.
var data = [
{title:'Team Schedules',backgroundImage:'images/tableview/off_1.png', hasChild:true, test:'team-schedules.js',
selectedBackgroundImage:'images/tableview/on_1.png', leftImage: 'images/tableview/phone_playmovie.png'},
{title:'Team Rosters',backgroundImage:'images/tableview/off_2.png', hasChild:true, test:'team-rosters.js',
selectedBackgroundImage:'images/tableview/on_2.png', leftImage: 'images/tableview/phone_camera.png'},
{title:'Coaches Corner',backgroundImage:'images/tableview/off_4.png', hasChild:true, test:'coaches-corner.js',
selectedBackgroundImage:'images/tableview/on_4.png', leftImage: 'images/tableview/phone_orientation.png'},
{title:'Student Tickets Login',backgroundImage:'images/tableview/off_3.png', hasChild:true, url:'https://oss.ticketmaster.com/html/home.htmI?SPSID=0&SPID=2996&&DB_OEM_ID=7700&team=usf&l=EN&STAGE=1&CNTX=10477925&out=1',
selectedBackgroundImage:'images/tableview/on_3.png', leftImage: 'images/tableview/phone_photogallery.png'}
];
19 Answers
-
Accepted Answer
First fix the code at line 66
var webview = Titanium.UI.createWebview({
to
var webview = Titanium.UI.createWebView({
if this does't fix the issue
an alert with the e.rowData.url it displays what it should ?inside the click function
alert(e.rowData.url)
-
I suppose you want to get test and/or url data from the clicked row
the_table.addEventListener('click', function(e) { if ( e.row.rowData.test ) alert('we have test= '+ e.row.rowData.test ); if ( e.row.rowData.url ) alert('we have test= '+ e.row.rowData.url ); })
-
Tamas, I did what you suggested but received a compiling error when I inserted the code. Below is a pastie to my window code. Thanks
http://pastie.org/1046102
-
tableView.addEventListener...
not
table.addEventListener...
-
I replaced
table.addEventListener...
w/
tableView.addEventListener...
I am getting the following compiling error.
[WARN] JavaScript compiler reported "Expected '{' and instead saw 'alert'." at main-window.js:52 [WARN] JavaScript compiler reported "Expected '{' and instead saw 'alert'." at main-window.js:53
It seems like its not liking the
alert('we have test...
-
This is a warning generated by lint.
It's harmless.
Does the code work?
To get rid of the warning you will have to do
if ( e.row.rowData.test ) { alert('we have test= '+ e.row.rowData.test ); }
-
No more errors, thanks. But when I click on the links, nothing happens.
my previous code looked like this
tableView.addEventListener('click', function(e) { if (e.rowData.test) { var win = Titanium.UI.createWindow({ url:e.rowData.test, title:e.rowData.title }); Titanium.UI.currentTab.open(win,{animated:true}); } });
When I had this code, I was at least able to click and navigate with [test]. I couldn't find a way to get the external url [url] to work when clicked though. Thank you for you response and help.
-
I have even tried, but [url] still doesn't open up a webview.
tableView.addEventListener('click', function(e) { if (e.rowData.test) { var win = Titanium.UI.createWindow({ url:e.rowData.test, title:e.rowData.title }); Titanium.UI.currentTab.open(win,{animated:true}); } if (e.rowData.url) { var webview = Ti.UI.createWebView(); } });
-
some things:
with e.rowData you get only the custom properties you define for a row( test, url ), title is not one of them.
So access it with e.row.titleYou will have to create a webview inside the new opened window and pass the url to this, not to the window.
-
"You will have to create a webview inside the new opened window and pass the url to this, not to the window."
Sounds good, how would I go about doing that?
would I just create a new .js file for that page?
-
This should do the trick , as long as test points to a .js file on the device and url points to an html page or a remote url ( code is not tested )
tableView.addEventListener('click', function(e) { var win = Titanium.UI.createWindow({ title:e.rowData.title }); if (e.rowData.test) { win.url=e.rowData.test; } if (e.rowData.url) { var webview = Titanium.UI.createWebview({ url:e.rowData.url }); win.add(webview); } Titanium.UI.currentTab.open(win,{animated:true}); });
-
My [test] is pointing to a .js file on the device and [url] is pointing to.
url:'https://oss.ticketmaster.com/html/home.htmI?SPSID=0&SPID=2996&&DB_OEM_ID=7700&team=usf&l=EN&STAGE=1&CNTX=10477925&out=1',
[test] is working properly when clicked, but [url] still isn't opening up a webview; nothing happens when [url] is clicked. Thank you for your patience.
-
It should work, can you make a new pastie with the whole part of this code?
-
Sure thing, thank you.
http://pastie.org/1046195
-
mmm weird
if you make an alert with e.rowData.url it returns what it should ?
you could try also to change "var win" to "var detail_win" inside the event function.
It shouldn't conflict with the win declared on line 1 but who knows :)
-
Could I try and make a new window .js file and house the webview within that new window so I could just use [test] for all my links?
If I could, could you provide a pastie of what this window would like?
- basic window with on_open webview state
Thank you for all of your assistance.
-
if you alert e.rowData.url what it does ?
-
hehe
createWebview is
createWebView
Let me know
-
Im not following you.
How do you alert something?
if you alert e.rowData.url what it does?
or
hehe createWebview is createWebView Let me know