how to redirect from one page to tab in another pa

2019-09-11 03:22发布

I have two pages in my application. The first page has a tab group with three tabs. Now on click of button in second page, I need to redirect my control to first tab 2 in my first page. How can I do that.

My code is as follows,

<Alloy>
  <TabGroup id="myTabGrp"> //Tabgroup Added
    <Tab id="one">
        <Window class="container">
            <Label>This is the Home View</Label>
        </Window>
    </Tab>

    <Tab id="two">
        <Window class="container" id="winTwo">
            <Label>This is the second View</Label>
        </Window>
    </Tab>

    <Tab id="three">
        <Window class="container">
            <Button onClick="saveLang">Proceed</Button>
        </Window>
     </Tab>
  </TabGroup>
</Alloy>

second page,

 <Alloy>
    <Window class="container">
                    <Button onClick="submitFun">submit</Button>
                </Window>
    </Alloy>


function submitFun()
{
var homeWindow = Alloy.createController('index').getView();
homeWindow.open({transition:Titanium.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
}

I don't wat load the full index page because it will take long time to load. I need to load only one tab in the index page. How can I do that?

1条回答
Deceive 欺骗
2楼-- · 2019-09-11 04:00

I think you would have the code in index.js from where you open your second page; maybe like :

Alloy.createController('second').getView().open();

Now in second.js you can just call close method of the window to close current window and return back to index.

function submitFun()
{
   $.second.close(); //id of second window = second
}

Also now add a focus event listener in index.js for the tabgroup and navigate to the desired tab.

$.myTabGrp.addEventListener('focus',function(e) { 
   $.myTabGrp.setActiveTab($.two);
});
查看更多
登录 后发表回答