【问题标题】:Can i use a use variable in Fullcalendar for render events data?我可以在 Fullcalendar 中使用 use 变量来渲染事件数据吗?
【发布时间】:2016-02-04 13:13:12
【问题描述】:

我在 WordPress 中将 Fullcalendar 用于我的活动日历插件。我正在使用 WordPress wp_localize_script 函数,以便可以将我的 PHP 变量用作 JavaScript 变量。这是我的本地化代码

    // - json items -
    $jsonevents[]= array(
        'title' => $post->post_title,
        'allDay' => false, // $stime,
        'start' => $st,
        'end' => $et,
        'url' => get_post_type_archive_link('event')
        );
    endforeach;
    else :
    endif;

$sawon =  json_encode($jsonevents);
wp_localize_script( 'fullcalendar', 'localized_script',$sawon);

这是我的 jquery 脚本

$(function() {
    ("#calendar").fullCalendar({
        header :{
                    left: 'prev,next today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay'
                },
        events : localized_script
    });
});

我的 Fullcalendar 没有显示任何事件,但 localized_script 在我的浏览器中可用。控制台还使用我的localized_script value 显示一个名为“加载资源失败”的错误。问题是什么,解决办法是什么?

【问题讨论】:

    标签: php wordpress fullcalendar boilerplate


    【解决方案1】:
    $jsonevents= array(
            'title' => 'post_title',
            'allDay' => false, // $stime,
            'start' => '2017-01-01',
            'end' => '2017-01-03',
            'url' => 'archive link'
            );
    
    $sawon =  json_encode($jsonevents);
    
    wp_localize_script($this->plugin_name, 'local_script',
        array( 
            'ajax_url' => wp_make_link_relative(admin_url( 'admin-ajax.php' )),
            'ajax_nonce' =>$sawon,
            )
        );
    

    Here 是浏览器控制台中的本地化脚本结果。

    【讨论】:

      猜你喜欢
      • 2016-02-26
      • 1970-01-01
      • 2013-05-26
      • 1970-01-01
      • 2017-10-15
      • 2021-10-28
      • 1970-01-01
      • 1970-01-01
      • 2015-08-07
      相关资源
      最近更新 更多