所以我想使用這個插件:http://w3widgets.com/responsive-calendar/的Javascript PHP的foreach
而且日曆初始化的方式,有添加的事件是,像這樣:
<script>
<?php $today = date('Y-m'); ?>
$(document).ready(function() {
$(".responsive-calendar").responsiveCalendar({
time: '<?php echo $today; ?>',
events: {
"2014-04-30": {"number": 1, "badgeClass": "badge-warning", "url": "http://w3widgets.com/responsive-calendar"},
"2013-04-26": {"number": 1, "badgeClass": "badge-warning", "url": "http://w3widgets.com"},
"2013-05-03": {"number": 1, "badgeClass": "badge-error"},
"2013-06-12": {}}
});
});
</script>
我想生成與事件因爲事件都存儲在數據庫中,所以這是一個foreach。我試圖做到以下幾點:
events: { <?php foreach($events as $event): ?> "<?php echo $event->date; ?>"...
但我得到的是說,在($events as $event)
的)
是意外的錯誤。
我該怎麼做,我必須能夠或日曆必須消失。乾淨利落。
UPDATE
如果我var_dump()
的$events
我得到以下字符串(縮短到第一個事件!)
array(3) { [0]=> object(stdClass)#21 (5) { ["id"]=> string(1) "1" ["name"]=> string(17) "State Large Group" ["school"]=> string(9) "NHS Bands" ["date"]=> string(9) "4-16-2014" ["showHome"]=> string(1) "1" }...
,如果我events: <?php echo json_encode($events); ?>
它不編碼如正確的順序。它的作用:
events: [{"id":"1","name":"State Large Group","school":"NHS Bands","date":"4-16-2014","showHome":"1"},{"id":"2","name":"State Solo\/Ensemble","school":"NHS Bands","date":"4-26-2014","showHome":"1"},{"id":"3","name":"League Music Festival","school":"RVMS Bands","date":"4-29-2014","showHome":"1"}] });
當它需要是這樣的:
"2013-06-12": {}
您是否用括號試過了? <?php foreach($ events as $ event){?>「<?php echo $ event-> date;?>」 – Steve
也許提供給我們實際的代碼部分? –
如果您向我們展示'$ events'獲取其內容的位置,我們可以爲您提供幫助。 – snwflk