1

想要使用 jQuery-jTable 插件 ( jtable.org ) 从数据库中获取(和添加/编辑)记录。我已将所需的脚本排入队列并验证它们是通过页面源加载的,但我什么也没得到。根据入门指南,我至少应该得到一个空白表,但我得到一个空白页。我的代码在下面——有什么想法吗?

将脚本排入队列的代码:

function lfc_load_scripts() {
//set global variables
global $plugin_url;

//set variable to use to point to process.php path
$js_vars = array('plugin_url'=>$plugin_url,);

//Load scripts and css for Tabs UI
wp_enqueue_script('jquery-ui-tabs');
wp_enqueue_script('lfc-ui-js', $plugin_url . 'includes/js/tabs-ui.js', array('jquery'));
wp_localize_script( 'lfc-ui-js', 'js_vars', $js_vars) ;
wp_register_style( 'lfc_jquery_admin_css', $plugin_url . 'includes/css/ui.css', false, '1.0.0' );
    wp_enqueue_style( 'lfc_jquery_admin_css' );

//Load scripts and css for jTable
    wp_enqueue_script('jquery-ui-core');
    wp_enqueue_script('lfc-jtable-js', $plugin_url . 'includes/js/jtable/jquery.jtable.js', array('jquery'));
wp_register_style( 'lfc_jtable_css', $plugin_url . 'includes/js/jtable/themes/metro/blue/jtable.css', false, '1.0.0' );
    wp_enqueue_style( 'lfc_jtable_css' );

    //Load main jQuery file
wp_enqueue_script('lfc-process-js', $plugin_url . 'includes/js/process.js', array('jquery'));

}
add_action('admin_enqueue_scripts', 'lfc_load_scripts');

这是 jQuery(根据 jTable.org 页面上的说明)

$('#FighterTableContainer').jtable({
        title: 'Table of people',
        actions: {
            listAction: '/GettingStarted/PersonList',
            createAction: '/GettingStarted/CreatePerson',
            updateAction: '/GettingStarted/UpdatePerson',
            deleteAction: '/GettingStarted/DeletePerson'
        },            
        fields: {
            PersonId: {
                key: true,
                list: false
            },
            Name: {
                title: 'Author Name',
                width: '40%'
            },
            Age: {
                title: 'Age',
                width: '20%'
            },
            RecordDate: {
                title: 'Record date',
                width: '30%',
                type: 'date',
                create: false,
                edit: false
            }
        }
});
4

1 回答 1

0

我在一个虚拟插件中测试了 jTable,它显示了一个带有声明字段(NameAgeRecordDate的空白表。

您的代码存在问题:

1)以下内容:

wp_enqueue_script( 'jquery-ui-tabs' );
wp_enqueue_script( 'lfc-ui-js', $plugin_url . 'includes/js/tabs-ui.js', array('jquery'));

可以声明为:

wp_enqueue_script(
    'lfc-ui-js', 
    $plugin_url . 'includes/js/tabs-ui.js', 
    array( 'jquery', 'jquery-ui-tabs' ) 
);

脚本也是如此'lfc-jtable-js'。也许,您的代码需要在footer上排队。

2)用 包装您的代码(document).ready,如下所示:

jQuery(document).ready(function($) {   
    $('#FighterTableContainer').jtable({
        // rest of the code
    });
});
于 2013-04-12T15:06:37.077 回答