gwt 中的菜单栏
我正在 gwt 中使用 MenuBar 控件并想要获取所选项目。我阅读了 API 文档 MenuBar的API文档,但找不到任何可以帮助我的方法。请告诉我如何捕获菜单栏的所选项目。我想在用户单击它时获取所选项目。
I am using MenuBar control in gwt and want to get the selected item. I read the API document API document for MenuBar but could not find any method that could help me. Please tell me the way how can I trap the selected item of the MenuBar.I want to get the selected item when the user click on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题的答案是命令。
http://google -web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/user/client/Command.html。
当您将项目添加到菜单栏(或其任何子项)时,您可以指定
或
您也可以独立于任何菜单项执行该命令:
The answer to your question is Command.
http://google-web-toolkit.googlecode.com/svn/javadoc/2.3/com/google/gwt/user/client/Command.html.
When you add an item to the menubar (or to any of its children) you specify
or
You could also execute the command independent of any menu items:
我不明白为什么 getSelectedItem() 方法不起作用。也许是因为您想在用户点击时拥有该项目?只需使用一个命令来创建菜单项,该命令询问菜单栏选择了哪个项目。也许对某些项目使用单独的命令可能会更好。
尼科
I don't see why the method getSelectedItem() wouldn't work. Maybe it is because you want to have the item when the user clicks? Just create your MenuItems with a Command that asks the MenuBar which item is selected. Maybe it might even be better to use a separate command for some of your items.
Nico
我有同样的问题并解决如下:
你可以检查它是否为空(如果不为空则清除它)
I've the same problem and solved as follow:
and you can check it for null (if not null then clear it)