2013-09-01 109 views
1

我仍然有在Emberjs jQuery datepicker的問題。這是我的codeDatePicker:ui.destroy不是一個函數

如果我用我的datepicker離開頁面,控制檯給了我錯誤:ui.destroy不是一個函數。

JQ.Widget = Em.Mixin.create({ 

didInsertElement: function() { 
    "use strict"; 
    var options = this._gatherOptions(), ui; 
    this._gatherEvents(options); 

    if (typeof jQuery.ui[this.get('uiType')] === 'function') { 
     ui = jQuery.ui[this.get('uiType')](options, this.get('element')); 
    } else { 
     ui = this.$()[this.get('uiType')](options); 
    } 

    this.set('ui', ui); 
}, 

willDestroyElement: function() { 
    "use strict"; 
    var ui = this.get('ui'), observers, prop; 

    if (ui) { 
     observers = this._observers; 
     for (prop in observers) { 
      if (observers.hasOwnProperty(prop)) { 
       this.removeObserver(prop, observers[prop]); 
      } 
     } 
     ui._destroy(); 
    } 
}, 

_gatherOptions: function() { 
    "use strict"; 
    var uiOptions = this.get('uiOptions'), options = {}; 

    uiOptions.forEach(function (key) { 
     options[key] = this.get(key); 

     var observer = function() { 
      var value = this.get(key); 
      this.get('ui')._setOption(key, value); 
     }; 

     this.addObserver(key, observer); 

     this._observers = this._observers || {}; 
     this._observers[key] = observer; 
    }, this); 

    return options; 
}, 

_gatherEvents: function (options) { 
    "use strict"; 
    var uiEvents = this.get('uiEvents') || [], self = this; 

    uiEvents.forEach(function (event) { 
     var callback = self[event]; 

     if (callback) { 
      options[event] = function (event, ui) { callback.call(self, event, ui); }; 
     } 
    }); 
} 
}); 

Ember調用willDestroyElement函數,但「ui._destroy()不是函數」爲什麼? 此代碼工作正常

回答

0

我已經受夠了以下變化成功outher jQuery的元素(自動完成,按鈕...):

替換:

ui._destroy(); 

有了:

if (ui._destroy) ui._destroy(); 
else if (ui.datepicker) ui.datepicker('destroy'); 

如果你想支持更多的沒有_destroy()的UI控件,你可能需要添加更多的代碼。