philippfrenzel / yii2fullcalendar

JQuery Fullcalendar Yii2 Extension
GNU General Public License v2.0
132 stars 95 forks source link

Why is there no data when the page is refreshed? I re write a method with Ajax, the background can also get the data, how to render? This is a little unclear. #103

Open yingzzai opened 6 years ago

yingzzai commented 6 years ago

<?php

use yii\helpers\Url; use yii\helpers\Html; use yii\web\JsExpression; use yii\web\AssetBundle; use yii\jui\JuiAsset; use app\models\Calendar; use yii\philippfrenzel\yii2fullcalendar;

/ @var $this yii\web\View / //$this->title = 'yii2 extension yii2-fullcalendar demo';

$DragJS = <<<EOF / initialize the external events -----------------------------------------------------------------/

$('#external-events .fc-event').each(function() { // store data so the calendar knows to render an event upon drop $(this).data('event', { title: $.trim($(this).text()), // use the element's text as the event title stick: true // maintain when user navigates (see docs on the renderEvent method) }); // make the event draggable using jQuery UI $(this).draggable({ zIndex: 999, revert: true, // will cause the event to go back to its revertDuration: 0 // original position after the drag }); });

EOF;

$this->registerJs($DragJS);

?>

'calendar', 'clientOptions' => [ 'selectable' => true, 'selectHelper' => true, 'droppable' => true, 'editable' => true, 'drop' => new JsExpression($JSDropEvent), 'select' => new JsExpression($JSCode), 'eventClick' => new JsExpression($JSEventClick), 'defaultDate' => date('Y-m-d') ], 'events' => $events, 'ajaxEvents' => Url::toRoute(['/calendar/jsoncalendar']), )); ?>
philippfrenzel commented 6 years ago

Hi, can you pls. make the code more readable? After a page refresh it should move back to "initial state" ;)

yingzzai commented 6 years ago

Thank you for your advice.

I got the data from the background, JSON format, can not be rendered on the page.

Is there any way? Even refresh, the data also appears on the page.

philippfrenzel commented 6 years ago

hmm, I think you need to call the jQuery('id').refresh() function to clear historical values?!

philippfrenzel commented 6 years ago

@yingzzai did the refresh work out?