2014-09-25 18 views
0

我想知道一個組合框是否已經打開,並調用一個函數,當它從商店加載數據時顯示進度條。我已經檢查了API,但是沒有發現我正在做的事情。如何使用Dojo捕獲ComboBox上打開的事件?

編輯

我想要做的是,而組合框從商店開始填充進度條。我用組合框和進度條(自定義類)創建了一個小部件,並使用aspect.before「裝飾」了openDropDown函數。這是我寫的代碼:

postCreate: function() { 
     this.inherited(arguments); 
     aspect.before(
      this.comboBox, 'openDropDown', 
      lang.hitch(this, function(){ 
       this.progressBar.increase(); 
      }) 
     ); 
     on(
      this.comboBox, 
      'search', 
      lang.hitch(this.progressBar, 'decrease') 
     ); 
    } 

但是它似乎並沒有使用正確的progressBar對象。

回答

0

這聽起來像你正在尋找像「onOpen」事件。從Dojo 1.10開始Dijit/Combobox小部件不支持您正在描述的事件,但它支持許多其他可能滿足您需求的事件。

我建議尋找到的API可能事件的列表:http://dojotoolkit.org/api/

但是下面的代碼將創建一個自定義「的OnOpen」事件像你所描述的。我已經提供了演示這一新的事件

http://jsfiddle.net/kagant15/z4nvzy44/

var comboBox = new ComboBox({ 
    id: "stateSelect", 
    name: "state", 
    value: "California", 
    store: stateStore, 
    searchAttr: "name" 
}, "stateSelect") 

// grab the existing openDropDown method 
var openDropDownFunction = comboBox.openDropDown; 
newFunction = function(){ 
    topic.publish("openDropDown") // add the custom "openDropDown" event trigger 
    return openDropDownFunction.apply(this); 
} 

// replace the old comBox method will our new function 
comboBox.openDropDown = newFunction; 

// Subscribe to the custom openDropDown event and do something when it fires 
topic.subscribe("openDropDown", function(){ 
    console.log("Open Drop Down even trigger"); 
}); 
+0

我已經試過您的解決方案,但似乎並不在我的情況下工作的jsfiddle。我用更多的信息編輯了原始問題。 – danielmaxx 2014-09-26 09:43:53

+0

你能爲你的作品創作一個小提琴嗎? – 2014-09-26 14:10:49

相關問題