我在 Twig 中渲染嵌套数组时遇到问题。这是我的 PHP 逻辑,我可以在其中获取其他字段,例如名称 URL,但不能获取数组数据。请检查树枝代码,我想我在那里做错了什么。错误:在渲染模板期间抛出异常(“注意:数组到字符串的转换”)。foreach ($arrays as $array) { foreach ($array as $key => $value) { $allProjects[$key][] = $value; }} {% for project in projects %} <tr> <td>{{ project.name }}</td> <td>{{ project.url }}</td> <td>{{ project.assingedApprover }}</td> <td></td> </tr> {% endfor %}JSON 数据 [ { "name": "Resolute Energy Corporation", "url": "http://msu.edu", "assignedAprover": [ { "firstName": "Joe", "lastName": "lastName" }, { "firstName": "men", "lastName": "gen" } ] }, { "name": "CBL & Associates Properties, Inc.", "url": "http://acquirethisname.com", "assignedAprover": [ { "firstName": "Joe", "lastName": "lastName" }, { "firstName": "men", "lastName": "gen" } ] },]
1 回答
子衿沉夜
TA贡献1828条经验 获得超3个赞
与assignedAprover数组一样,您可以使用以下命令对其进行迭代for:
{% for project in projects %}
<tr>
<td>{{ project.name }}</td>
<td>{{ project.url }}</td>
{% for aprover in project.assignedAprover %}
<td>{{ aprover['first_name'] }} {{ aprover['last_name'] }}</td>
{% endfor %}
<td></td>
</tr>
{% endfor %}
- 1 回答
- 0 关注
- 115 浏览
添加回答
举报
0/150
提交
取消