在父构造参数中,如果ajax设置为true,js\\u vars将输出到页面的页脚。
/**
* Constructor. The child class should call this constructor from it\'s own constructor
*
* @param array $args An associative array with information about the current table
* @access protected
*/
function __construct( $args = array() ) {
$args = wp_parse_args( $args, array(
\'plural\' => \'\',
\'singular\' => \'\',
\'ajax\' => false
) );
$screen = get_current_screen();
add_filter( "manage_{$screen->id}_columns", array( &$this, \'get_columns\' ), 0 );
if ( !$args[\'plural\'] )
$args[\'plural\'] = $screen->base;
$args[\'plural\'] = sanitize_key( $args[\'plural\'] );
$args[\'singular\'] = sanitize_key( $args[\'singular\'] );
$this->_args = $args;
if ( $args[\'ajax\'] ) {
// wp_enqueue_script( \'list-table\' );
add_action( \'admin_footer\', array( &$this, \'_js_vars\' ) );
}
}
在页脚中获得输出的默认javascript变量在js\\u vars函数中定义:
/**
* Send required variables to JavaScript land
*
* @access private
*/
function _js_vars() {
$current_screen = get_current_screen();
$args = array(
\'class\' => get_class( $this ),
\'screen\' => array(
\'id\' => $current_screen->id,
\'base\' => $current_screen->base,
)
);
printf( "<script type=\'text/javascript\'>list_args = %s;</script>\\n", json_encode( $args ) );
}