简体   繁体   English

在 Flex 选项卡式视图导航器之间切换

[英]Switch between Flex Tabbed ViewNavigators

I am working on a Flex TabbedViewNavigatorApplication with three tabs (ViewNavigator elements).我正在开发一个带有三个选项卡(ViewNavigator 元素)的 Flex TabbedViewNavigatorApplication I would like to switch from one ViewNavigator to another based upon a user action (via ActionScript code).我想根据用户操作(通过 ActionScript 代码)从一个 ViewNavigator 切换到另一个。

I know that switching between Views uses pushView and popView , but I'm working with ViewNavigators, and my searching revealed nothing useful.我知道视图之间的切换使用pushViewpopView ,但我正在使用 ViewNavigators,我的搜索显示没有任何用处。

I'm trying to switch from Tab2 to Tab1 when an event occurs.发生事件时,我正在尝试从 Tab2 切换到 Tab1。 In this case, Tab2 contains a list, and when the user makes a selection, I want to jump back to Tab1.在这种情况下,Tab2 包含一个列表,当用户进行选择时,我想跳回 Tab1。

<s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark"
                                  creationComplete="onAppReady(event)">
    <s:ViewNavigator label="Tab1" width="100%" height="100%" firstView="views.TabOneView"/>
    <s:ViewNavigator label="Tab2" width="100%" height="100%" firstView="views.TabTwoView"/>
    <s:ViewNavigator label="Tab3" width="100%" height="100%" firstView="views.TabThreeView"/>
</s:TabbedViewNavigatorApplication>

Thanks for your help!谢谢你的帮助!

I use the following line of ActionScript to switch from one ViewNavigator to another based on a user action:我使用以下 ActionScript 行根据用户操作从一个ViewNavigator切换到另一个:

TabbedViewNavigator(navigator.parentNavigator).selectedIndex = 1;

It worked like a charm and seems simpler than bubbling events.它就像一个魅力,看起来比冒泡事件更简单。

This class is strangely undocumented.这个 class 奇怪地没有记录。 I have not tried this myself, but from searching online, this is what I found which corroborates with what the rest of the network does.这个我自己没有试过,但是从网上搜索发现,这和网络的rest的做法是相符的。

What you need to do is bubble an event to the TabbedViewNavigatorApplication and from there change the selectedIndex property to whichever tab you need to change to.您需要做的是将事件冒泡到TabbedViewNavigatorApplication并从那里将selectedIndex属性更改为您需要更改的任何选项卡。 For example:例如:

<s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark"
                                  creationComplete="onCreationComplete()">
    <fx:Script>
        <![CDATA[
            private function onCreationComplete():void
            {
                this.addEventListener('someEvent', someHandler);
            }

            private function someHandler(e:Event):void
            {
                this.selectedIndex = 0; // or whatever index you want. 
            }
        ]]>
    </fx:Script>
    <s:ViewNavigator label="Tab1" width="100%" height="100%" firstView="views.TabOneView"/>
    <s:ViewNavigator label="Tab2" width="100%" height="100%" firstView="views.TabTwoView"/>
    <s:ViewNavigator label="Tab3" width="100%" height="100%" firstView="views.TabThreeView"/>
</s:TabbedViewNavigatorApplication>

You just need to dispatch a bubbling event from within your children.你只需要从你的孩子内部发送一个冒泡事件。 You could event create a custom event that holds data about which tab to switch to.您可以事件创建一个自定义事件,其中包含有关切换到哪个选项卡的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM