반응형
Passing parameters on JQuery .trigger
I am using JQuery trigger but am not sure what the correct syntax is to pass parameters in my situation. Here is where I am making the call :
$('#'+controlName).trigger(event);
Here is where I am doing the event binding :
$(window).on('onPartialRendered', onPartialRendered);
And here is my event handler :
var onPartialRendered = function () {
.....
};
Everything works fine until I try to pass parameters. What would be the correct way to do it as per my example?
First parameter is always string with event name and next parameters are additional data:
.trigger('foo', [1, 2]);
.on('foo', function(event, one, two) { ... });
Special thanks for Rocket Hazmat
Example:
var controller = {
listen: function (event, json, string) {}
};
$('body').trigger('this_works', [{data: [1, 2, 3]}, 'something']);
$('body').on('this_works', function (event, json, string) {
controller.listen(event, json, string);
});
Remote partial:
Please do not use this way. There is many article about this problem in network. This take much time and generate unnecessary traffic in network. Please use this way:
var template = $('#templates #example_template').detach();
var clone = template.clone();
clone.find('.some_field').val('new_data');
clone.attr('id', null);
$('table tbody').append(clone);
참고URL : https://stackoverflow.com/questions/16401538/passing-parameters-on-jquery-trigger
반응형
'Nice programing' 카테고리의 다른 글
Python Module with a dash, or hyphen (-) in its name (0) | 2020.10.21 |
---|---|
Getting binary (base64) data from HTML5 Canvas (readAsBinaryString) (0) | 2020.10.21 |
How do you Hover in ReactJS? - onMouseLeave not registered during fast hover over (0) | 2020.10.21 |
좋은 Haskell 코딩 표준 (0) | 2020.10.21 |
“구조 나 노조가 아닌 구성원 '*******'에 대한 요청”은 무엇을 의미합니까? (0) | 2020.10.21 |