2012-06-07 95 views
0

这是我的代码,预期的菜单显示祖父母>父母>孩子。 但是,“父”项没有显示,而是直接在“祖父母”下面显示“孩子”。Flex:不显示菜单项

<mx:Script> 
    <![CDATA[ 
     // Import the Menu control. 
     import mx.controls.Menu; 

     // Create and display the Menu control. 
     private function createAndShow():void { 
      var myMenu:Menu = Menu.createMenu(null, myMenuData, false); 
      myMenu.labelField="@label"; 
      myMenu.show(10, 10); 
     } 
    ]]> 
</mx:Script> 

<!-- Define the menu data. --> 
<mx:XML format="e4x" id="myMenuData"> 
    <root> 
     <menuitem label="grandparent"> 
      <menuitem label="parent"> 
       <menuitem label="child"/> 
      </menuitem> 
     </menuitem> 
    </root> 
</mx:XML> 

<mx:VBox> 
    <!-- Define a Button control to open the menu --> 
    <mx:Button id="myButton" 
       label="Open Menu" 
       click="createAndShow();"/> 
</mx:VBox> 

有趣的是,当我添加第二个亲本,它正确地显示菜单。 任何人都可以解释这里发生了什么,我怎么能解决这个问题?

回答

0

我把你的代码扔到了我自己的项目中,得到了和你一样的结果。然后,我添加了另一个家长到您的XML和一切正常。我猜测,如果你只有一个父节点,那么真的不需要显示它,所以它跳到了孩子身上。 下面添加第二父:

<root> 
    <menuitem label="grandparent"> 
     <menuitem label="parent1"> 
      <menuitem label="child"/> 
     </menuitem> 
     <menuitem label="parent2"> 
      <menuitem label="child"/> 
     </menuitem> 
    </menuitem> 
</root> 
+0

我也注意到的事情是,有时我刚1父,有时2,但我想我的界面保持一致。我想我们应该考虑这个错误。 – Pmarcoen

0

尝试像下面的一些事情: -

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"> 
    <fx:Declarations> 
     <!-- Place non-visual elements (e.g., services, value objects) here --> 
     <fx:XML id="myMenuData" > 
       <menuitem label="grandparent"> 
        <menuitem label="Uparent"> 
         <menuitem label="child"/> 
        </menuitem> 
       </menuitem> 
     </fx:XML> 
    </fx:Declarations> 
    <fx:Script> 
     <![CDATA[ 
     // Import the Menu control. 
      import mx.controls.Menu; 

      // Create and display the Menu control. 
      private function createAndShow():void { 
       var myMenu:Menu = Menu.createMenu(null, myMenuData, true); 
       myMenu.labelField="@label"; 
       myMenu.show(10, 10); 
      } 
     ]]> 
    </fx:Script> 

    <!-- Define the menu data. --> 


    <mx:VBox> 
     <!-- Define a Button control to open the menu --> 
     <mx:Button id="myButton" 
        label="Open Menu" 
        click="createAndShow();"/> 
    </mx:VBox> 

</s:Application>