I use jQuery widget factory (jQuery widgets) for my js widgets.
$.widget('cool.someWidget', {
options: {
someEvent: null
}
// other js code
});
Normally to run the widget from js you write
$(selector).someWidget({
someEvent: function() { ..... }
});
In Yii I use CJSON::encode to compile all the initialization properties which include the someEvent event.
echo CJSON::encode(array(
'someEvent' => 'function() {....}',
));
However due to the conversion (CJSON), it converts the function() {…} to a string so in the document it is written the following
$(selector).someWidget({
someEvent: "function() { .... }"
});
because the someEvent is actually a string when I call the this._trigger(‘someEvent’) it doesn’t run the code.
This problem I have only when I "generate" the view and not with Ajax requests (which I handle differently in the system). Is there some way of making Yii actually write in the document the function withought the quotes?
p.s. My alternative is to bind the event on another statement but I would really like to avoid that
$(selector).on('onSomeEvent', .... );