【问题标题】:In a GROQ query can you get each asset's data in an array of image references?在 GROQ 查询中,您可以在图像引用数组中获取每个资产的数据吗?
【发布时间】:2023-03-25 01:27:01
【问题描述】:

我的架构中有一组图像,一个画廊。我想用我的 GROQ 查询返回数组中每个图像的图像 url。

如果我这样做 image{asset->} 它可以工作,对于单个图像。

对于实际查询的示例,我正在尝试这样的事情:

*[_type == 'gallery'] {_id, title, description, images[asset->]} 

我正在使用视觉插件来处理这个查询。它返回一个空数组。

【问题讨论】:

    标签: sanity


    【解决方案1】:

    我相信正确的语法是:

    *[_type == 'gallery']{
        _id, 
        title,
        description,
        images[]{
          asset->{url}
        }
     }
    

    如果您只需要直接在 images 键上的 URL 数组:

    "images": images[].asset->url
    

    【讨论】:

      猜你喜欢
      • 2022-10-17
      • 2019-11-30
      • 2021-04-30
      • 1970-01-01
      • 2016-07-10
      • 1970-01-01
      • 1970-01-01
      • 2022-11-13
      • 2015-06-01
      相关资源
      最近更新 更多