Javascript 如何使用不同选项卡中的按钮链接到选项卡组中的特定选项卡';窗户在哪里?
我有一个有5个选项卡的选项卡组,其中一个选项卡是“主页”屏幕。我希望用户能够单击任何选项卡窗口中的按钮返回主屏幕 目前,我找到的最接近的方法创建了一个新窗口,这会中断导航Javascript 如何使用不同选项卡中的按钮链接到选项卡组中的特定选项卡';窗户在哪里?,javascript,mobile,titanium,Javascript,Mobile,Titanium,我有一个有5个选项卡的选项卡组,其中一个选项卡是“主页”屏幕。我希望用户能够单击任何选项卡窗口中的按钮返回主屏幕 目前,我找到的最接近的方法创建了一个新窗口,这会中断导航 var win_home = Titanium.UI.createWindow({ url:'home.js' }); btn_home.addEventListener("click", function() { Ti.UI.currentTab.open(win_home,{animated:true}); });
var win_home = Titanium.UI.createWindow({
url:'home.js'
});
btn_home.addEventListener("click", function() {
Ti.UI.currentTab.open(win_home,{animated:true});
});
在按钮事件侦听器下添加此代码
// get the tab group object in the file
var tabGroup = Titanium.UI.currentTabGroup;
btn_home.addEventListener("click", function() {
// pass the id of your home tab, i used 1 here
tabGroup.tabs[1].active = true;
});
为什么不使用内置方法
tabGroup.setActiveTab(INDEX)
?另外,您的主选项卡索引很可能是0而不是1,因为JS数组从0开始。注释中提到了选项卡的索引。tabGroup.setActiveTab(INDEX)主要用于app.jsMuhammad,您的解决方案工作得很好,谢谢。正如Brian提到的,我确实将索引更改为0。我很好奇你是在哪里发现这些东西的,因为似乎有些基本信息我找不到。