Flex4 ContextMenu() 不显示添加的项目

发布于 2024-10-22 09:43:54 字数 281 浏览 8 评论 0 原文

我正在尝试使用 ContextMenu() 在 Flex 4 中显示上下文菜单。

此处提供完整渲染代码 http://pastebin.com/Kx8tJ1cY 问题是,

当我向其中添加项目时,上下文菜单不会更改。

谁能告诉我如何向 Flex 中的列表框添加自定义右键菜单(不使用外部 JS,仅按照 Adob​​e 的意图使用 ContextMenu。

请谢谢 克雷格

I am trying to use ContextMenu() to display context menus in Flex 4.

Full Render code here http://pastebin.com/Kx8tJ1cY

The problem is that the context menu does not change when I add items to it.

Can anyone show me how to add a custom right click menu to a List box in flex (without using external JS, just using ContextMenu as Adobe intended.

Please and Thank you
Craig

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

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

发布评论

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

评论(2

苍风燃霜 2024-10-29 09:43:54

我找到了问题/解决方案。如果有 Vbox 或选项卡导航器,则无法使用上下文菜单。这很疯狂,因为这意味着我无法正确进行相对布局或体面的可变宽度设计。

引用自:http://help.adobe。 com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html

例如,如果 DataGrid 控件是 TabNavigator 或 VBox 容器的子级,则 DataGrid 控件不能有自己的上下文菜单。

I found the problem/solution. You cant use context menus if there are Vboxes or Tab Navigators. Which is insane because it means I cant do relative layout properly or decent variable width design.

Quoted from: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/ui/ContextMenu.html

For example, if a DataGrid control is a child of a TabNavigator or VBox container, the DataGrid control cannot have its own context menu.

陌伤浅笑 2024-10-29 09:43:54

您是否尝试过将 ListcontextMenu 属性设置为上下文菜单? FlexExamples 有一个 DataGrid 组件发布的>类似示例List 不应有太大不同。

沿着这些思路:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            [Bindable]
            private var cm:ContextMenu;

            private var alert:Alert;

            private function init():void {
                var cmi:ContextMenuItem = new ContextMenuItem("View item...", true);
                cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);

                cm = new ContextMenu();
                cm.hideBuiltInItems();
                cm.customItems = [cmi];
                cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenu_menuSelect);
            }

            private function contextMenu_menuSelect(evt:ContextMenuEvent):void {
                dataGrid.selectedIndex = lastRollOverIndex;
            }

            private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void {
                var obj:Object = dataGrid.selectedItem;
                alert = Alert.show("Property A: " + obj.@propertyA + "\\n" + "Property B: " + obj.@propertyB, obj.@label, Alert.OK);
            }
        ]]>
    </mx:Script>

    <mx:XML id="itemsXML">
        <items>
            <item label="Item 1" data="i001" propertyA="Item 1.A" propertyB="Item 1.B" />
            <item label="Item 2" data="i002" propertyA="Item 2.A" propertyB="Item 2.B" />
            <item label="Item 3" data="i003" propertyA="Item 3.A" propertyB="Item 3.B" />
            <item label="Item 4" data="i004" propertyA="Item 4.A" propertyB="Item 4.B" />
            <item label="Item 5" data="i005" propertyA="Item 5.A" propertyB="Item 5.B" />
            <item label="Item 6" data="i006" propertyA="Item 6.A" propertyB="Item 6.B" />
            <item label="Item 7" data="i007" propertyA="Item 7.A" propertyB="Item 7.B" />
            <item label="Item 8" data="i008" propertyA="Item 8.A" propertyB="Item 8.B" />
        </items>
    </mx:XML>

    <mx:Number id="lastRollOverIndex" />

    <mx:DataGrid id="dataGrid"
            width="400"
            dataProvider="{itemsXML.item}"
             contextMenu="{cm}"
             itemRollOver="lastRollOverIndex = event.rowIndex">
        <mx:columns>
            <mx:DataGridColumn id="labelCol"
                    dataField="@label"
                    headerText="Label:" />

            <mx:DataGridColumn id="propACol"
                    dataField="@propertyA"
                    headerText="Property A:" />

            <mx:DataGridColumn id="propBCol"
                    dataField="@propertyB"
                    headerText="Property B:" />
        </mx:columns>
    </mx:DataGrid>

    <mx:Label text="{dataGrid.selectedItem.@label}" />

</mx:Application>

Have you tried setting the contextMenu property of the List to you context menu? FlexExamples has a similar example posted for the DataGrid component. A List shouldn't be too different.

Something along these lines:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/08/20/using-a-custom-context-menu-with-the-flex-datagrid-control/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()">

    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;

            [Bindable]
            private var cm:ContextMenu;

            private var alert:Alert;

            private function init():void {
                var cmi:ContextMenuItem = new ContextMenuItem("View item...", true);
                cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, contextMenuItem_menuItemSelect);

                cm = new ContextMenu();
                cm.hideBuiltInItems();
                cm.customItems = [cmi];
                cm.addEventListener(ContextMenuEvent.MENU_SELECT, contextMenu_menuSelect);
            }

            private function contextMenu_menuSelect(evt:ContextMenuEvent):void {
                dataGrid.selectedIndex = lastRollOverIndex;
            }

            private function contextMenuItem_menuItemSelect(evt:ContextMenuEvent):void {
                var obj:Object = dataGrid.selectedItem;
                alert = Alert.show("Property A: " + obj.@propertyA + "\\n" + "Property B: " + obj.@propertyB, obj.@label, Alert.OK);
            }
        ]]>
    </mx:Script>

    <mx:XML id="itemsXML">
        <items>
            <item label="Item 1" data="i001" propertyA="Item 1.A" propertyB="Item 1.B" />
            <item label="Item 2" data="i002" propertyA="Item 2.A" propertyB="Item 2.B" />
            <item label="Item 3" data="i003" propertyA="Item 3.A" propertyB="Item 3.B" />
            <item label="Item 4" data="i004" propertyA="Item 4.A" propertyB="Item 4.B" />
            <item label="Item 5" data="i005" propertyA="Item 5.A" propertyB="Item 5.B" />
            <item label="Item 6" data="i006" propertyA="Item 6.A" propertyB="Item 6.B" />
            <item label="Item 7" data="i007" propertyA="Item 7.A" propertyB="Item 7.B" />
            <item label="Item 8" data="i008" propertyA="Item 8.A" propertyB="Item 8.B" />
        </items>
    </mx:XML>

    <mx:Number id="lastRollOverIndex" />

    <mx:DataGrid id="dataGrid"
            width="400"
            dataProvider="{itemsXML.item}"
             contextMenu="{cm}"
             itemRollOver="lastRollOverIndex = event.rowIndex">
        <mx:columns>
            <mx:DataGridColumn id="labelCol"
                    dataField="@label"
                    headerText="Label:" />

            <mx:DataGridColumn id="propACol"
                    dataField="@propertyA"
                    headerText="Property A:" />

            <mx:DataGridColumn id="propBCol"
                    dataField="@propertyB"
                    headerText="Property B:" />
        </mx:columns>
    </mx:DataGrid>

    <mx:Label text="{dataGrid.selectedItem.@label}" />

</mx:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文