在 JQuery.touch 上传递参数

我正在使用 JQuery 触发器,但不确定在我的情况下传递参数的正确语法是什么。这就是我打电话的地方:

$('#'+controlName).trigger(event);

下面是我进行事件绑定的地方:

$(window).on('onPartialRendered', onPartialRendered);

这是我的事件处理程序:

var onPartialRendered = function () {


.....
};

在我尝试传递参数之前,一切都很正常。根据我的例子,正确的方法是什么?

91347 次浏览

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);