您的位置:首页 > 其它

titanium开发教程-04-05从rows打开window

2012-03-17 15:27 344 查看


android无法打开,ios支持

app.js

 

// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();

var win = Titanium.UI.createWindow({
title:"Tours",
backgroundColor:"#FFFFFF",
//navBarHidden:true, //Hide the nav bar for the window
tabBarHidden:true //Hide the tab bar for the window
});
//Remember, we are hiding this tab through the property tabBarHidden above
var tab = Titanium.UI.createTab({
icon:"KS_nav_views.png",
title:"Tours",
window:win
});

var data = [
{title:"Backpack Cal", leftImage:"images/01-backpack-cal-thumb.png", className:"tableRow"},
{title:"California Calm", leftImage:"images/02-calm-cal-thumb.png", className:"tableRow", hasDetail:true, customData:"This is custom row data"},
{title:"California Hotsprings", leftImage:"images/03-hotsprings-cal-thumb.png", className:"tableRow"},
{title:"Cycle California", leftImage:"images/04-cycle-cal-thumb.png", className:"tableRow"},
{title:"From Desert to Sea", leftImage:"images/05-desert-cal-thumb.png", className:"tableRow"},
{title:"Kids California", leftImage:"images/06-kids-cal-thumb.png", className:"tableRow", hasDetail:true, customData:"This is custom row data"},
{title:"Nature Watch", leftImage:"images/07-nature-watch-cal-thumb.png", className:"tableRow"},
{title:"Snowboard Cali", leftImage:"images/08-snowboard-cal-thumb.png", className:"tableRow",hasDetail:true,js:"external.js",dataToPass:"This data was passed in from the main window"},
{title:"Taste of California", leftImage:"images/09-taste-cal-thumb.png", className:"tableRow"}
]

var tableView = Titanium.UI.createTableView({
data:data
});

tableView.addEventListener("click",function(e){
//Check the row's hasDetail property
if(e.source.hasDetail){
if(e.source.js){//Does the row have a pointer to an external js file?
//It does: Load that file
var w = Titanium.UI.createWindow({
title:e.source.title,//Take the title from the row
backgroundColor:"#FFFFFF",
dataToPass:e.source.dataToPass,
url:e.source.js//The url property of a window will load an external .js file for window contents (be sure that external file is properly formatted!)
});
}else{
//It doesn't: Create a window from scratch
var w = Titanium.UI.createWindow({
title:e.source.title,//Take the title from the row
backgroundColor:"#FFFFFF",
})
//Create some views for our window

var label = Titanium.UI.createLabel({
text:"A newly opened window from the " + e.source.title + " row",
width:"auto",
height:"auto",
textAlign:"center"
});

w.add(label)
}
//Slide-open the window
tab.open(w,{animated:true});//Try it without the animated:true and see what happens
}else{//Row doesn't have a window to open
alert("No window to open :(")
}
});

win.add(tableView);

tabGroup.addTab(tab);

// open tab group
tabGroup.open();


 

 

external.js

 

//Create a pointer to the current window context
var win = Titanium.UI.currentWindow;

var label = Titanium.UI.createLabel({
text:win.dataToPass,//This text is loaded from variables passed into the window through the dataToPass property
width:"auto",
height:"auto",
textAlign:"center"
});

win.add(label);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: