在 Flex 中加载和设置菜单的保存值

发布于 2024-12-28 15:14:58 字数 172 浏览 3 评论 0原文

我在 Flex 中有一个简单的弹出菜单,即 mx 菜单,并且我使用 Menu.initMenu 来创建依赖于定义为数据提供者的 XML 列表的菜单。

菜单有复选框项目,每次我在包含菜单实例的类中调用 load(values:Array) 函数时,我想检查相关项目。

如何动态加载值并更改菜单的选择?

I have a simple popup menu in flex, a mx Menu, and I use the Menu.initMenu to create the menu relying on an XML List defined as the data provider.

The menu has check box items, and every time I call a load(values:Array) function in the class which contains the menu's instance, I want to check the relevant items.

How do I dynamically load values and change the menu's selections ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

允世 2025-01-04 15:14:58

好的,明白了:

  1. 设置菜单,并给每个菜单项一个标签属性:

    private var subMenuDataMain:XMLList = new XMLList(
        "" +
        “<菜单标签=''类型='分隔符'/>” +
        "" +
        "");
    
  2. 创建一个辅助函数来打开给定标签的菜单项(如果是 2 级菜单项,还提供 subMenuID,是第二个项目的标签名称):

    函数toggleMenuItem(menuID:字符串,subMenuID:字符串,切换:布尔值):void
        {
            if (子菜单ID != "")
                subMenuDataSets.(@label == menuID).menuitem.(@label == subMenuID).@toggled = 切换;
            别的
                subMenuDataSets.(@label == menuID).@toggled = 切换;
        }
    
  3. 实现一个函数初始化菜单的值:

    public function setMenuOptions(obj:SampleObject):void {
        toggleMenuItem("SHOW_DEMO", "", (obj.demoISShown());
     }
    

OK, got it :

  1. set the menu, and give EVERY menuitem a label attribute :

    private var subMenuDataMain:XMLList = new XMLList(
        "<menuitem label='Title' icon='' enabled='false'/>" +
        "<menuitem label='' type='separator'/>" +
        "<menuitem label='SHOW_DEMO' type='check' eventName='SHOW_DEMO' />" +
        "<menuitem label='' type='separator'/>");
    
  2. create an auxiliary function to turn on menuitems for a given Label (if it's a 2-level menu item, provide also the subMenuID which is the second item's label name):

        function toggleMenuItem(menuID:String, subMenuID:String, toggle:Boolean):void
        {
            if (subMenuID != "")
                subMenuDataSets.(@label == menuID).menuitem.(@label == subMenuID).@toggled = toggle;
            else
                subMenuDataSets.(@label == menuID).@toggled = toggle;
        }
    
  3. implement a function that initializes the menu's values :

    public function setMenuOptions(obj:SampleObject):void {
        toggleMenuItem("SHOW_DEMO", "", (obj.demoISShown());
     }
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文