2017-10-18 42 views
1

我處於不得不在同一個項目中使用jQuery和YUI的位置。我使用的引導多選 - http://davidstutz.github.io/bootstrap-multiselect/YUI不會在使用引導多選時觸發on.change

我想下面的代碼YUI:

this.level1 = this.Y.one("#menu"); 
this.level1.on('change',this.getAjax,this); 

現在,這時候下拉菜單沒有啓用多選工作。一旦發現,getAjax未被解僱。

任何想法?我猜(從谷歌檢查)實際菜單沒有改變?

當我嘗試使用jQuery來看看是否有改變,我可以得到它的工作,但在嘗試運行getAjax()當錯誤

$('#menu').on('change', function(evt, params){ 
    this.getAjax(); 
} 

錯誤是

this.getAjax is not a function(…) 

的代碼片斷較大

​​

所以我可以看到,如果它通過jQuery變化,但我怎麼會那麼叫getAjax

+0

因爲多選組件都有自己的變化情況,因此它不火你應該使用multiselect插件事件onChange http://davidstutz.github.io/bootstrap-multiselect/#configuration-options-onChange –

+0

我不能得到那個發射YUI功能,但是 - 這就是問題所在 – pee2pee

回答

1

可以在此從任何事件,因爲那個時候「這一」被引用到您的項目無法訪問,因此,您必須使用以下

constructor: function() { 
var $this = this; 
$('#menu').on('change', function(evt, params){ 
    //this.getAjax();//this is your '#menu' item 
    $this.getAjax(); 
}); 

    }, 

    /** 
    * Sample widget method. 
    */ 
    methodName: function() { 

    }, 

    /** 
    * Makes an AJAX request for `default_ajax_endpoint`. 
    */ 
    getAjax: function() { 
+0

所以顯然很簡單..... 謝謝 – pee2pee

相關問題