将属性更改为数组元素

时间:2017-05-06 02:44:09

标签: php laravel

我使用了这个https://fullcalendar.io/完整日历jquery插件。

我有事件表,我可以获得如下事件:

public function index()
{
    $events=Event::all();
    return view('index')->with('events',$events);
}

$event->event_date$event->name会提供活动日期和活动名称。我需要将事件名称添加到日历中的相应日期吗?

我试过这个:

$('#calendar').fullCalendar({
    events:[
            {
                title:'{{$events[0]->name}}',
                start:'{{$events[0]->event_date}}'
             }
           ]
});

这只会给出数组中的第一个事件。但是,我怎样才能获得所有活动而不只是一个?因为title数组中没有start$events?或者基本上我只需要一个循环?

1 个答案:

答案 0 :(得分:1)

尝试mapWithKeys

import numpy as np

#convert the list of tuples l_tuples to a numpy array:
l_new = np.array(l_tuples)

#calculate the mean and standard deviation of the first column
mean=np.mean(l_new,axis=0)[0]
std=np.std(l_new,axis=0)[0]

#create a mask to find all elements which are in the interval [mean-std, mean+std]
mask=[abs(x[0]-mean)<std for x in l_new]

#pictures you want to use:
accepted = l_new[mask]
#pictures you dont want to use:
remove = l_new[[not i for i in mask]]

在您的刀片模板中

public function index()
{
    $events=Event::all();
    $keyed = $collection->mapWithKeys(function ($item) {
        return ['title' => $item['name'], 'start' => $item['event_date']];
    });
    return view('index')->with('events',$keyed);
}