Flex:菜单栏、菜单点击
我不知道为什么,但我看到菜单栏上的 itemclick 事件不会触发,除非您单击子项目。
处理位于顶层并且没有子菜单项的菜单项的点击的干净方法是什么。
例如,我想在单击 MenuItem B 时触发一个事件。
<?xml version="1.0"?>
<!-- menus/MenuBarControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:MenuBar id="myMenuBar" labelField="@label" itemClick="{itemClick(event)}" >
<mx:XMLList>
<menuitem label="MenuItem A">
<menuitem label="SubMenuItem A-1"/>
<menuitem label="SubMenuItem A-2"/>
</menuitem>
<menuitem label="MenuItem B"/>
</mx:XMLList>
</mx:MenuBar>
</mx:Application>
I do not know why but I see that itemclick event on a menubar do not fired unless you click a sub item.
What is the clean way to handle clicks on menuitems which are on the top level and do not have sub menu items.
For example I want to fire an event whenever MenuItem B is clicked.
<?xml version="1.0"?>
<!-- menus/MenuBarControl.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:MenuBar id="myMenuBar" labelField="@label" itemClick="{itemClick(event)}" >
<mx:XMLList>
<menuitem label="MenuItem A">
<menuitem label="SubMenuItem A-1"/>
<menuitem label="SubMenuItem A-2"/>
</menuitem>
<menuitem label="MenuItem B"/>
</mx:XMLList>
</mx:MenuBar>
</mx:Application>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想这会有所帮助,
在下面的菜单栏中,
我还添加了一个属性“索引”。作为 XML,我们可以在其中添加除某些关键字之外的任何元素。
“ItemClick”事件将处理子项,“Click”事件将处理顶级菜单栏项(父项)。
希望这有帮助。
问候,
普拉卡什
Guess this can help,
Fof the following menubar,
Here i ve also added a property 'index'. As an XML we can add any element in it except for some of the keywords.
The "ItemClick" event will take of the childrens, and the "Click" will take care of the toplevel menubar items(parents).
Hope this helps.
Regards,
Prakash
此行为是设计使然。想象一下,如果它是浏览器中的菜单栏:单击文件、编辑、查看等顶级项目只会显示弹出窗口,它们不会触发任何操作。
来自
MenuBar
的 livedocs 页面< /a>如果您必须在顶级项目单击上执行某些操作,请侦听
MenuBar
上的click
事件,并遍历parent
链>event.target 搜索MenuBarItem
,这是MenuBar
顶级项目的默认项目渲染器This behavior is by design. Think if it as the menu bar in your browser: clicking on top level items like File, Edit, View etc just shows the popup, they don't trigger any action.
From the livedocs page for
MenuBar
If you must do something on top level item click, listen to the
click
event on theMenuBar
and traverse through theparent
chain of theevent.target
searching for aMenuBarItem
, the default item renderer for top level items of aMenuBar
flex 开箱即用的菜单栏有很多限制。例如我不能有像这样的嵌套子菜单
顶部菜单
- 1级菜单
-2级菜单
- 3级菜单......
为了解决这个问题,需要在每个子菜单中添加一个额外的菜单,这确实很痛苦。
The menu bar which flex gives out of the box has lot of limitations .For instance i cannot have a nested submenu like
top_menu
-level 1 menu
-level 2 menu
-level 3 menu.....
to counter this one need to add an extra menu in each sub-menu which is pain indeed.