繁体   English   中英

如何将数据循环到 laravel 刀片 javascript 中的数组中?

[英]How to loop the data into an array in laravel blade javascript?

在我的 Laravel 5.3 项目中,我在 controller 中有这个来实现比赛表数据:

public function list(){
$data=Competition::all();
return view('map', ['data'=> $data]);
}

路线:

Route::get('map', 'Api\CompetitionsController@list');

使用这些代码行,我的 map.blade.php (在 html 区域中)有五列(两个帖子):

<ul>
@foreach ($data As $i)
{{ $i->id }} {{ $i->name }} {{ $i->contact_city }} {{ $i->lat }} {{ $i->lng }}
@endforeach
</ul>

我得到了五列(两篇文章)的打印输出,如下所示:

1 Fälttävlan Landskrona 55.87 12.83 2 Fälttävlan Sundsvall 62.39 17.31

在我的 map 脚本区域中,我想为数据库表中的每个帖子创建一个包含这些示例五个数据的数组,以在 map 上创建标记。 我怎么做? $data 包含数据库表中的所有内容,不仅是数据,还有列名等。

我解决了这个问题。 这段代码做到了:

var locations = [
    @foreach ($data as $i)
         [ "{{ $i->name }}  " + "{{ $i->contact_city }}" , {{ $i->lat }},{{ $i->lng }},0, 'https://test.webshooter.se/app/competitions/'+{{ $i->id }}+ '/information'],
         @endforeach         
];

该代码位于 map 脚本中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM