关于 jQuery UI 的 datepicker 小部件作为 EmberJS Mixin 的另一件事。如果你想提供一个回调函数来处理 beforeShowDay 事件,你会引发这个错误:
Uncaught TypeError: Cannot read property '0' of undefined
即使您的回调函数(在您的 ember 视图中)返回一个数组,就像它在 jqueryui 文档中指定的那样
beforeShowDay: function(date){
some code...
return [true, ''];
};
发生这种情况是因为在 _gatherEvents 函数中的 callback.call 之后没有返回任何内容
_gatherEvents: function(options) {
var uiEvents = this.get('uiEvents') || [], self = this;
uiEvents.forEach(function(event) {
var callback = self[event];
if (callback) {
// You can register a handler for a jQuery UI event by passing
// it in along with the creation options. Update the options hash
// to include any event callbacks.
options[event] = function(event, ui) { callback.call(self, event, ui); };
}
});
}
我通过在 callback.call 之前添加一个 return 语句来解决这个问题。
_gatherEvents: function(options) {
var uiEvents = this.get('uiEvents') || [], self = this;
uiEvents.forEach(function(event) {
var callback = self[event];
if (callback) {
// You can register a handler for a jQuery UI event by passing
// it in along with the creation options. Update the options hash
// to include any event callbacks.
options[event] = function(event, ui) { return callback.call(self, event, ui); };
}
});
}
工作示例http://jsfiddle.net/thibault/qf3Yu/