EasyUI provides callback functions as part of most of the widgets' options' objects. A user can easily
set the event listener on any number of events, e.g. onOpen, onSelect, onResize, etc...
However, there is no ability, out of the box, to
add an event listener, except of course to set a listener that retransmits the event from the one and only handler to other listeners.
Is it possible to utilize jQuery triggers on your widgets for your event listeners in options so the user can more easily (and more loosely coupled)
add event listeners with $().on, or $().one. For example
$('#grid-object').datagrid('on', 'onLoadSuccess', postLoadAction_one);
$('#grid-object').datagrid('on', 'onLoadSuccess', postLoadAction_two);
// or
$('#grid-object').on('onLoadSuccess', postLoadAction_one);
$('#grid-object').on('onLoadSuccess', postLoadAction_two);
// or
$('#grid-object').datagrid('options').on('onLoadSuccess', postLoadAction_one);
$('#grid-object').datagrid('options').on('onLoadSuccess', postLoadAction_two);
Here is something I use in my project to make it more of an Observable pattern
var onChangeTrigger = function(newValue, oldValue) {
$(this).trigger('onChange', [newValue, oldValue]);
};
var triggerEventOnKeyPress = function(jq) {
$(jq[0]).textbox('textbox').on('keydown', function(e) {
$(jq[0]).trigger('onKeyPress', [e]);
});
};
$.extend($.fn.textbox.defaults, {
onChange: onChangeTrigger
});
$.extend($.fn.textbox.methods, {
triggerEventOnKeyPress: triggerEventOnKeyPress
});
$.extend($.fn.numberbox.methods, {
onChange: onChangeTrigger, triggerEventOnKeyPress: triggerEventOnKeyPress
});
$.extend($.fn.combo.defaults, {
onChange: onChangeTrigger
});