Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Wordpress Gutenberg ACF阻止打开块时如何添加JS_Javascript_Wordpress_Wordpress Gutenberg_Gutenberg Blocks - Fatal编程技术网

Javascript Wordpress Gutenberg ACF阻止打开块时如何添加JS

Javascript Wordpress Gutenberg ACF阻止打开块时如何添加JS,javascript,wordpress,wordpress-gutenberg,gutenberg-blocks,Javascript,Wordpress,Wordpress Gutenberg,Gutenberg Blocks,我使用的是ACF块,下面有一个块 acf_register_block_type(array( 'name' => 'columns', 'title' => __('Columns'), 'description' => __('For complex multi colomn rows.'), // 'category' => 'formatting',

我使用的是ACF块,下面有一个块

acf_register_block_type(array(
    'name'              => 'columns',
    'title'             => __('Columns'),
    'description'       => __('For complex multi colomn rows.'),
    // 'category'          => 'formatting',
    'render_template'   => get_template_directory() . '/includes/blocks/templates/columns.php',
    'enqueue_style'     => get_template_directory_uri() . '/includes/blocks/css/columns.css',
    'enqueue_script'    => get_template_directory_uri() . '/includes/blocks/js/columns.js',
    'keywords' => array('rows', 'content', 'column'),
    'supports' => array('align' => array('wide', 'full')),
    'mode' => 'auto',
));
当我点击编辑器中的块打开它进行编辑时,我需要运行一些JS。我不知道是否有一个标准的方法来实现这一点,所以我想我可以使用一个点击事件来运行我的函数,但它不会启动。下面是DOM中块的图片

我在下面添加了脚本。(底部有一个“添加块脚本”示例)

这是我的精简版JS

(function($){
    var initializeBlock = function ($block) {

        $('body').on('click', 'div[data-type="acf/columns"]', function () {
            console.log('teeeeeeeest');
        });

        //... Other JS put here works
    }

    if (window.acf) {
        window.acf.addAction('render_block_preview/type=columns', initializeBlock);
    }

})(jQuery);
为什么这个点击功能不会启动?还有别的办法吗