【问题标题】:How to iterate over tabs in flex tabbar如何遍历 flex tabbar 中的选项卡
【发布时间】:2023-10-10 13:19:01
【问题描述】:

我是弹性新手。我需要通过配置禁用指定的弹性标签栏中的一些标签。我在遍历选项卡栏中的选项卡时遇到问题。如果我使用 getChildAt() 命令,它不会禁用选项卡按钮,而是禁用该选项卡按钮的内容,所以它不好。

感谢和问候, 莫希特兰卡

【问题讨论】:

    标签: actionscript-3 flex3


    【解决方案1】:

    在询问代码时,请始终发布最小的测试用例。 getChildAt() 会起作用,所以您的代码还有其他问题。

    <mx:Script>
        <![CDATA[
            import mx.events.ItemClickEvent;
            import mx.controls.tabBarClasses.Tab;
            private function clickTab(event:ItemClickEvent):void {
                var target:TabBar = event.currentTarget as TabBar;
                var currTab:Tab;
                var parity:int = event.index & 1;
                /* disable all tabs at indices w/ same parity as clicked tab;
                   enable tabs of opposite parity.
                 */
                for (var i=0; i<target.numChildren; ++i) {
                   currTab = target.getChildAt(i) as Tab;
                   currTab.enabled = (i&1)^parity;
                }
            }
        ]]>
    </mx:Script>
    
    <mx:TabBar id="someTabs" itemClick="clickTab(event)">
        <mx:dataProvider>
            <mx:String>Foo</mx:String>
            <mx:String>Bar</mx:String>
            <mx:String>Baz</mx:String>
            <mx:String>Bam</mx:String>
        </mx:dataProvider>
    </mx:TabBar>
    

    【讨论】:

      【解决方案2】:

      为什么不使用绑定到您的配置?

      类似

         enabled="{yourConfiguration.lastResult.enabled}"
      

      【讨论】:

      • 因为需求比这更复杂。瓶颈是我不知道如何遍历标签栏中的标签。
      【解决方案3】:

      对于那些想要 Flex 4.5(也可能是 Flex 4)有效答案的人。我终于想出了一个解决办法。这对我来说就像是一种黑客行为,但 Adob​​e 没有接听电话,它对我有用。这是一个简化的示例。

      <!-- component that has the the TabBar in it... -->
      
      <fx:Script>
          <![CDATA[
      //imports here
      
      import mx.core.UIComponent;
      
      //imports
      
      private function setTabEnabled(index:int,enabled:Boolean):void{
          var theTab:UIComponent = theTabBar.dataGroup.getElementAt(index) as UIComponent;
          if(theTab){theTab.enabled = enabled;}
      }
      ]]>
      </fx:Script>
      
      <s:TabBar id="theTabBar"
          dataProvider="{viewStack}"/>
      
      <mx:ViewStack id="viewStack">
          <s:NavigatorContent label="0th Tab">
              <!-- ...Content -->
          </s:NavigatorContent>
          <s:NavigatorContent label="1st Tab">
              <!-- ...Content -->
          </s:NavigatorContent>
          <s:NavigatorContent label="2nd Tab">
              <!-- ...Content -->
          </s:NavigatorContent>
      </mx:ViewStack>
      
      <!-- rest of the component that has the the TabBar in it... -->
      

      然后您只需在事件处理程序中调用setTabEnabled(theTabIndex,trueFalse),该处理程序与决定选项卡启用或未启用的原因有关。

      应该扩展 TabBar 以支持这一点,但我已经花了足够的时间试图弄清楚。

      快乐编码 =D

      【讨论】:

        最近更新 更多