如何在 Contentstack JS API 响应中包含引用的条目

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

我有一个内容堆栈 API 调用,如下所示:

const Entry = Stack.ContentType('home').Entry("blt5e6d02158a314e4c");

Entry.fetch()
.then(function success(entry) {
    console.log(entry.toJSON());
})

返回这样的响应:

{
 "_version":13,
 "locale":"en-us",
 "uid":"blt5e6d02158a314e4c",
 "modular_blocks":[
    {
       "banner":{
          "title":"Test banner title",
          "background_image":null
       }
    },
    {
       "listing":{
          "title":"Test listing",
          "food_items":[
             {
                "uid":"blt3dc93d9d43186dd3",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt9b3e1baeb2e3fe17",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"bltf74ee44deee6501b",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt3a164e1dcdf7fd8b",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt9093f3bb9135e7b1",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blta1e533c66e8cf57a",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt67728d24e4e704f2",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt5af3ad110269ac72",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt7a263ba68a1a39eb",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt85cef2ca76051a6e",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt857356711e1637a6",
                "_content_type_uid":"food_item"
             },
             {
                "uid":"blt446e027c9e069362",
                "_content_type_uid":"food_item"
             }
          ]
       }
    }
 ]
}

如何在此回复中包含“food_item”内容条目的详细信息?我真的需要单独查询其中每一个才能获取这些详细信息吗?

javascript api content-management-system headless contentstack
1个回答
0
投票

我发现了这一点,你必须在 Entry 上使用 .includeReference 方法,如下所示 ->

Entry
.includeReference(['modular_blocks.listing.food_items'])
.fetch()
© www.soinside.com 2019 - 2024. All rights reserved.