gpt4 book ai didi

reactjs - 如何在 Sanity.io 中的 inputComponent 中检索引用的字段数据?

转载 作者:行者123 更新时间:2023-12-04 01:45:32 25 4
gpt4 key购买 nike

在 Sanity Studio 中,我试图在输入组件中获取所有文档的属性。关注这篇文章 An officially supported way to get at the document content我能够使用 withDocument HOC 来获取文档数据,但其中一些具有“引用”类型,因此我只能获取 _ref 和 _type 而不是整个对象。我怎样才能做到?

最佳答案

您可以使用取消引用运算符 -> 取消引用这些值。因此,假设您有一个名为 book 的文档,其属性 author 是一个引用类型数组。
您可以通过以下方式获取作者数组的值:

const books = await client.fetch(
`*[_type == "book"] {
...,
authors[]->
}`
)
您可以查看 Sanity's docs在 GROQ 上查询更多更好的信息。

关于reactjs - 如何在 Sanity.io 中的 inputComponent 中检索引用的字段数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55428988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com