Obtener el widget selector de fecha de JQuery UI como EmberJS Mixin para que funcione
Frecuentes
Visto 2,072 veces
1
En este JsFiddle: http://jsfiddle.net/maxl/mCXND/
(copiado y modificado de http://jsfiddle.net/ud3323/XMgwV/)
Intento crear un Ember DatePicker basado en JQuery.
El primer problema con el que me encuentro es esta línea:
var ui = jQuery.ui[this.get('uiType')](options, this.get('element'));
jQuery.ui[this.get('uiType')] no devuelve una función, así que supongo que la solución con la que comencé funciona para algunos widgets de jQueryUI, pero no para todos. Me gustaría una solución que funcione para todos los widgets de JQuery-UI y, en particular, para el Selector de fecha de JQueryUI.
Muchas Gracias
2 Respuestas
3
Si observa el código jqueryui, verá que algunos de ellos se invocan como una función, otros no. Puedes resolverlo usando esto:
var ui;
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);
}
ejemplo de trabajo: http://jsfiddle.net/PzsrT/7/
Respondido 29 Oct 12, 15:10
2
Una cosa más sobre el widget selector de fecha de jQuery UI como EmberJS Mixin. Si desea proporcionar una función de devolución de llamada para manejar el evento beforeShowDay, generará este error:
Uncaught TypeError: Cannot read property '0' of undefined
incluso si su función de devolución de llamada (en su vista de brasas) devuelve una matriz, como se especifica en el documento jqueryui
beforeShowDay: function(date){
some code...
return [true, ''];
};
Esto sucede porque no se devuelve nada después de callback.call en la función _gatherEvents
_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); };
}
});
}
Arreglo esto agregando una declaración de devolución antes de 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) { return callback.call(self, event, ui); };
}
});
}
ejemplo de trabajo http://jsfiddle.net/thibault/qf3Yu/
Respondido 03 Oct 12, 18:10
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas jquery-ui ember.js or haz tu propia pregunta.
FYI this.$() es un atajo para $(this.get('element')) - cristobal swasey