2015-06-10 25 views
1

我有兩個views - 一個用於樹面板,一個用於上下文菜單(定義爲FilesEditor.view.FilesEditorContextMenu)。我有一個controller,其中它收聽itemcontextmenu事件。我不知道我應該如何創建(在哪個階段?)以及如何顯示我的FilesEditorContextMenu。聽者的部分看起來像這樣:顯示控制器中的上下文菜單

itemcontextmenu:function(view, rec, item, index, event){ 
    event.stopEvent(); 
    ... What should I do next? How should I instantiate and show a context menu 
} 

編輯

我調查這個example它具有類似的功能我想要什麼的代碼,但問題是 - 我無法找到執行getContextMenu() - 這是問題最重要的。

回答

1

這是一個示例代碼來打開上下文菜單(這會給你一些想法):

itemcontextmenu: function(view, record, item, index, e, eOpts) { 
     var position = e.getXY(), 
      menu = Ext.create('FilesEditor.view.FilesEditorContextMenu', { 
      id: 'myMenu', 
      items: [{ 
       text: 'Some Menu Item', 
       handler: function() { 
        // do your stuff 
       } 
      }], 
      listeners: { 
       mouseleave: function() { 
        // close menu 
        menu.close();// check documentation https://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.menu.Menu-method-close 
       } 
      } 
     }); 
     e.stopEvent(); // prevent the browser default context menu 
     menu.refView = view; // passing the view reference to the menu so that we can get a handle of the grid inside the menu item handler 
     menu.showAt(position); 
    } 
+0

我不知道這種做法是否會導致內存泄漏與否。由於每當用戶右鍵單擊時,都會創建一個新的上下文菜單實例。是否可以創建一次,然後重新使用它? – Jacobian

+0

您將在離開時關閉菜單。檢查更新的答案。 – Yellen