2011-01-27 20 views
0
  this.widgets.category = new YAHOO.widget.Button(this.id + "-category", 
      { 
       type: "split", 
       menu: this.id + "-category-menu" 
      });  

我使用上面的代碼來創建一個yui按鈕,之後我更新了菜單中的選項,但菜單無法更新。我可以使用什麼功能更新菜單?如何在YAHOO.widget.Button中動態加載菜單項?

在此先感謝!

回答

1

我們使用按鈕的菜單類型很多。通常,我們希望從頭開始重建所有選項。爲此,請嘗試以下操作:

// assumes btn is the YAHOO.widget.Button 
var menu = btn.getMenu(); 

// clear existing items 
menu.clearContent(); 

// code to add new menu items using either addItem() or addItems() 
menu.addItems([ 
    { text: "--Not Selected--", value: null }, 
    { text: "Option 1", value: "1" }, 
    { text: "Option 2", value: "2" } 
]); 

// forces menu to render 
menu.render();