以下是我的事件插件中的代码,我需要在自定义插件中重复使用。
我试图从我自己的自定义插件中调用此函数。当用户单击按钮时,我希望它调用以下函数。
my.render_fields = function( ticket_id, num ) {
var $row = $( '.tribe-event-tickets-plus-meta' ).filter( '[data-ticket-id="' + ticket_id + '"]' );
var $template = $row.find( '.tribe-event-tickets-plus-meta-fields-tpl' );
var $fields = $row.find( '.tribe-event-tickets-plus-meta-fields' );
var template_html = $template.html();
if ( ! my.has_meta_fields( ticket_id ) ) {
return;
}
var current_count = $fields.find( '.tribe-event-tickets-plus-meta-attendee' ).length;
var diff = 0;
if ( current_count > num ) {
diff = current_count - num;
$fields.find( '.tribe-event-tickets-plus-meta-attendee:nth-last-child(-n+' + diff + ')' ).remove();
return;
}
diff = num - current_count;
var i = 0;
for ( ; i < diff; i++ ) {
var tweaked_template_html = template_html;
tweaked_template_html = template_html.replace( /tribe-tickets-meta\[\]/g, 'tribe-tickets-meta[' + ticket_id + '][' + ( current_count + i + 1 ) + ']' );
tweaked_template_html = tweaked_template_html.replace( /tribe-tickets-meta_([a-z0-9\-]+)_/g, 'tribe-tickets-meta_$1_' + ( current_count + i + 1 ) + '_' );
$fields.append( tweaked_template_html );
}
};
我不确定如何将插件中的.js文件与该代码对话以便它可以使用它。
任何帮助表示感谢。
提前致谢。