从Laravel Blade中的JSON选择值 [英] Select value from JSON inside Laravel Blade
问题描述
我正在使用带有刀片和vuejs的laravel.使用列表控制器,我正在接收所有要显示的用户数据的正确响应.
I'm using laravel with blade and vuejs. Using a controller for a list I am receving the correct response with all the users data to show.
其中一些字段是json数据,我不明白如何检索单个值.
Some of this fields are json data and I can't understand how to retrieve single value.
`@foreach ($lista as $freelance)
<md-table-row>
<md-table-cell>
{{ $freelance->regione }}
</md-table-cell>
</md-table-row>
@endforeach`
$ freelance-> regione是JSON,在页面中正确显示为:
$freelance->regione is a JSON, correctly shown in the page as:
`{"text": "Veneto", "value": "Veneto"}`
我的问题是,如何获取JSON响应的单个值而不是所有数据?最好没有循环...我知道我可以为其使用新的循环,但是可能没有.
My question is, how can I get the single value of the JSON response and not all the data? Preferably without loops...I know that I can use a new loop for it but possible no..
推荐答案
在传递$lista
变量进行操作之前,请先在控制器中进行尝试.
Try this in your controller before passing the $lista
variable to view do this.
foreach($lista as list)
{
//we will decode the variable befoe passing it to view
$list->regione = json_decode($list->regione, true);
}
,然后将变量传递给您的视图,例如:
return View::make('your_view_name', compact('lista'));
然后在刀片视图中.
`@foreach ($lista as $freelance)
<md-table-row>
<md-table-cell>
{{ $freelance->regione['text'] }}
</md-table-cell>
<md-table-cell>
{{ $freelance->regione['value'] }}
</md-table-cell>
</md-table-row>
@endforeach`
这篇关于从Laravel Blade中的JSON选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!