Ember.js DatePicker:ui.destroy不是函数
我在Emberjs中仍然存在jQuery datepicker的问题。这是我的 若我带着日期选择器离开页面,控制台会给我一个错误:ui.destroy不是一个函数Ember.js DatePicker:ui.destroy不是函数,ember.js,Ember.js,我在Emberjs中仍然存在jQuery datepicker的问题。这是我的 若我带着日期选择器离开页面,控制台会给我一个错误:ui.destroy不是一个函数 JQ.Widget = Em.Mixin.create({ didInsertElement: function () { "use strict"; var options = this._gatherOptions(), ui; this._gatherEvents(options);
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.\u destroy()不是函数”为什么?
这段代码与其他jQuery元素(自动完成、按钮…)配合得很好我成功地进行了以下更改: 替换:
ui._destroy();
与:
如果要支持更多没有_destroy()的UI控件,可能需要添加更多代码
if (ui._destroy) ui._destroy();
else if (ui.datepicker) ui.datepicker('destroy');