jquery - 从 Wordpress 批量操作功能执行/调用 jquery
问题描述
最初,我没有在我的自定义 WP 插件中使用 WP_List_Table 并执行批量操作,我使用带有 onClick 事件的按钮来调用具有以下代码的 jQuery 函数;
<button type="button" onclick="selected_payout()" class="button">Pay Selected</button>
<button type="button" onclick="multi_withdaw()" class="button">Pay All</button>
现在,我决定在我的插件中使用 WP_List_Table 并且除了批量操作之外一切正常。下面是我的 prepare_items() 函数的代码;
public function prepare_items()
{
$columns = $this->get_columns();
$hidden = $this->get_hidden_columns();
$sortable = $this->get_sortable_columns();
$data = $this->table_data();
usort( $data, array( &$this, 'sort_data' ) );
$perPage = get_option('dragonpay_payout_settings')['entry_per_page'];
$currentPage = $this->get_pagenum();
$totalItems = count($data);
$this->set_pagination_args( array(
'total_items' => $totalItems,
'per_page' => $perPage
) );
$data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
$this->items = $data;
$this->process_bulk_action();
}
以下是我的批量操作功能,下拉菜单出现在页面中。但是,单击应用按钮时没有任何反应。我不知道如何有效地调用 jQuery。
public function get_bulk_actions() {
return array(
'pay_selected' => __( 'Pay Selected' ),
'pay_all' => __( 'Pay All' ),
);
}
public function process_bulk_action() {
// security check!
if ( isset( $_POST['_wpnonce'] ) && ! empty( $_POST['_wpnonce'] ) ) {
$nonce = filter_input( INPUT_POST, '_wpnonce', FILTER_SANITIZE_STRING );
$action = 'bulk-' . $this->_args['plural'];
if ( ! wp_verify_nonce( $nonce, $action ) )
wp_die( 'Nope! Security check failed!' );
}
$action = $this->current_action();
switch ( $action ) {
case 'pay_selected':
//call the jquery selected_payout()
break;
case 'pay_all':
//call the jquery multi_withdaw()
break;
default:
// do nothing or something else
return;
break;
}
return;
}
这个问题对其他人来说似乎很愚蠢,但我非常感谢您的建议和建议,以了解如何解决这个问题。
解决方案
推荐阅读
- c# - Process 提供 StandardOutput 后,如何更新进度条?
- awk - 如何使用 fish shell 将多行输出读入单个变量?
- python - 通过 3d 列表打印特定项目
- javascript - 有没有办法减少动态创建的每个孩子的边距,这样孩子就不会溢出父母
- python-3.x - 如何在treeview PyQt5中删除父项的子项
- python - Python:从文本文件的一行中删除一个字符串 python
- java - java.lang.OutOfMemoryError 尝试实现极小极大算法时
- c++ - _getcwd 不是返回当前工作目录,而是返回程序存储的地方
- angular - Angular - 为什么在分离的组件上调用生命周期挂钩?
- sql - 使用 SSIS 数据包运行作业时触发插入日期失败