为了避免表单中出现多行,我尝试使用raay中的键获取集合结果,但是它不起作用。这可能吗 ?怎么样?
<table>
<tr>
<td>
<div class="thumbnailLeftSmallIconTop">
<img class="thumbnailSmallImage" src="~/Content/images/house_50px.png" alt="Image">
<span> @Html.DisplayFor(modelItem => house) </span>
</div>
</td>
<td>
<div class="thumbnailLeftSmallIconBottom">
<img class="thumbnailSmallImage" src="~/Content/images/bedroom_80px.png" alt="Image">
<span> @Html.DisplayFor(modelItem => bedroom) </span>
</div>
</td>
</tr>
<tr>
<td>
<div class="thumbnailLeftSmallIconTop">
<img class="thumbnailSmallImage" src="~/Content/images/house_50px.png" alt="Image">
<span> @Html.DisplayFor(modelItem => house) </span>
</div>
</td>
<td>
<div class="thumbnailLeftSmallIconBottom">
<img class="thumbnailSmallImage" src="~/Content/images/bedroom_80px.png" alt="Image">
<span> @Html.DisplayFor(modelItem => bedroom) </span>
</div>
</td>
</tr>
</table>
我得到500错误:stdClass类的对象无法转换为字符串...
有什么想法吗?
答案 0 :(得分:0)
如果$collection
是array
或Collection
,例如:
$collection = [
"lundiStatus" => "foo",
"mardiStatus" => "foo"
];
或
$collection = new Collection([
"lundiStatus" => "foo",
"mardiStatus" => "foo"
]);
您可以通过以下方式访问:
@foreach($days as $day => $data)
<?php dd($collection[$data->status]); ?>
@endforeach
但是如果$collection
是object
,例如:
$collection = (object) array(
"lundiStatus" => "foo",
"mardiStatus" => "foo"
);
您可以通过以下方式访问:
@foreach($days as $day => $data)
<?php dd($collection->{$data->status}); ?>
@endforeach
有关语句中对象的访问属性值,请参见括号。