2013-10-22 14 views
5

jQuery UI Sortableを使用しようとすると、プラグインの作成中に問題が発生しました。私はCodexのような指示に従ったが、問題は残った。 jQueryのUIソート機能が機能せず、FirebugにTypeError: jQuery(...).sortable is not a functionと表示されます。WordPressの管理ページでjQuery UIをソート可能にする

は、私はWordPress 3.6上で動作していることだし、コードは次のとおりです。

<?php 
/* 
Plugin Name: Name 
Description: Description 
Version: 0.1 
Author: Bloorchi 
*/ 

add_action('admin_menu', 'my_plugin_admin_menu'); 

function my_plugin_admin_menu() { 
    add_action('admin_print_scripts-' . $page_hook_suffix, 'my_plugin_admin_scripts'); 
    $page_hook_suffix = add_submenu_page('edit.php', 'My Plugin', 'My Plugin', 'manage_options', 'my_plugin-options', 'my_plugin_manage_menu'); 
} 

function my_plugin_admin_scripts() { 
    wp_enqueue_script('jquery-ui-sortable'); 
} 

function my_plugin_manage_menu() { 
?> 
<table id="test"> 
    <tbody> 
     <tr> 
      <td>1</td> 
      <td>2</td> 
     </tr> 
     <tr> 
      <td>3</td> 
      <td>4</td> 
     </tr> 
     <tr> 
      <td>5</td> 
      <td>6</td> 
     </tr> 
    <tbody>  
</table> 
<script> 
    jQuery('table#test tbody').sortable(); 
</script> 
<?php 
} 

答えて

4

2つのことを、あなたはこれが反転してい:

$suffix = add_submenu_page( 
    'edit.php', 
    'My Plugin', 
    'My Plugin', 
    'manage_options', 
    'my_plugin-options', 
    'my_plugin_manage_menu' 
); 
add_action("admin_print_scripts-$suffix", 'my_plugin_admin_scripts'); 

そして、あなたは常にこのようにjQueryを実行する必要があります。

<script type="text/javascript"> 
jQuery(document).ready(function($) { 
    $('table#test tbody').sortable(); 
}); 
</script> 
+0

私はこの改造コードで正確なコードをテストしてOKです:http://pastebin.com/mXFSR9Bn – brasofilo

0

あなたのプラグインのすべてを無効にし、もう一度それを試してみてください。私も同様の問題があり、問題がプラグインの1つにあることが判明しました

関連する問題