2013-09-01 49 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控件,你可能需要添加更多的代码。