【发布时间】:2023-03-29 03:15:01
【问题描述】:
我有一个数组:
{ "id": 1,
"title": "Incidunt facere placeat nulla occaecati voluptatem voluptatem minus.",
"categories": [
{ "id": 1,
"name": "News",
"created_at": "2018-04-23 18:05:47",
"updated_at": "2018-04-23 18:05:47",
"pivot": {
"post_id": 1,
"category_id": 1 } }, {
"id": 2,
"name": "Sport",
"created_at": "2018-04-23 18:05:47",
"updated_at": "2018-04-23 18:05:47",
"pivot": {
"post_id": 1,
"category_id": 2
}
}
]}
我可以简单地使用{{post.title}} 来获得帖子标题,但是当我使用{{post.categories.name}} 时它会返回null,因为它不是数组。
反正有类别名称吗?
【问题讨论】:
-
post.categories是一个可以容纳许多类别(或没有类别)的数组。您希望以这种方式返回哪个名称? -
您在类别中有多个项目吗?