2013-03-25 122 views
0

菜單的一個選項被認爲是「典型的」。正如大多數人會點擊第一個菜單項。但對於這些外部情況,還有第二種選擇。因此,我想要一個按鈕菜單,對於那些不想爲「典型」選項點擊兩次的按鈕菜單。我在想,一個按鈕的處理程序將:Extjs按鈕點擊默認調用menuitem

  • 停止顯示菜單(我試過event.stopEvent()沒有成功。)
  • 調用的處理程序中的菜單項之一。

但是,如果您單擊按鈕旁邊的下拉圖標,仍然可以訪問菜單。

小提琴here。當您單擊箭頭部分

http://docs.sencha.com/ext-js/4-2/extjs-build/examples/build/KitchenSink/ext-theme-neptune/#split-buttons

菜單纔會顯示出來:

Ext.create('Ext.button.Button', { 
    text: 'Pick One', 
    menu: { 
     items: [{ 
      text: 'Thing 1!', 
      handler: function() { 
       alert('foo'); 
      } 
     }, { 
      text: 'Thing 2!', 
      handler: function() { 
       alert('bar'); 
      } 
     }] 
    }, 
    handler: function (theButton, event) { 
     //stop the menu from showing 
     //event.stopEvent(); //try to stop showing menu, but no luck 

     //invoke the handler for menu item 1 
     //try to get at handler for menuitem programmatically 
     //theButton.menu.items.getAt(0).??? 

     //i'd settle for hard-coding the function 
     //alert('foo'); 
    } 
}); 
+1

如果您只是直接觸發其中一個項目,那麼有菜單有什麼意義?爲什麼不只是讓按鈕處理程序執行它? – 2013-03-25 20:35:23

+0

我想在那裏有一個選項菜單(可以通過點擊下拉圖標來獲得),但是那裏有一個懶惰的默認選項。 – Andrea 2013-03-26 11:28:23

回答

1

在這種情況下,你應該使用拆分按鈕。當你點擊按鈕部分時,它會觸發按鈕處理程序而不顯示菜單。