在Api Platforms管理员列表中显示深场源

问题描述 投票:0回答:1

我正在使用最新的Api Platform Admin组件,并且试图在Ingredients列表上显示名称Category,而不是API IRI。如下所示,Category.name为空。Current state of my List in Admin Panel

我已定义列表:

const ingredientsList = props => (
    <ListGuesser {...props}>
        <FieldGuesser source="name" />
        <FieldGuesser source="category" />
        <TextField source="category.name" />
        <FieldGuesser source="description" />
    </ListGuesser>
);

[当我查看浏览器网卡时,我看到来自API的响应如下。

{
   "@context":"\/api\/contexts\/Ingredient",
   "@id":"\/api\/ingredients",
   "@type":"hydra:Collection",
   "hydra:member":[
      {
         "@id":"\/api\/ingredients\/1",
         "@type":"Ingredient",
         "name":"Orange",
         "category":{
            "@id":"\/api\/ingredient_categories\/1",
            "@type":"IngredientCategory",
            "name":"fruits"
         },
         "description":"Orange."
      }
   ],
   "hydra:totalItems":1
}

但是当我在基于控制台中React-admin文档的“ console.log”部分的自定义MyTextField中执行Writing your own component时,会看到:

{
   "@id":"/api/ingredients/1",
   "@type":"Ingredient",
   "name":"Orange",
   "category":"/api/ingredient_categories/1",
   "description":"Orange.",
   "id":"/api/ingredients/1"
}

这里发生了什么?为什么console.log中的对象不同,以及如何在列表中显示Category名称而不是IRI?

javascript react-admin api-platform.com
1个回答
0
投票

为了在react-admin中显示子资源,您需要使用<ReferenceField> https://marmelab.com/react-admin/Fields.html

© www.soinside.com 2019 - 2024. All rights reserved.