无法从 Contentful 中的 getEntry 获取值

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

我想使用 contentful v10 Node.js 18 从 contentful 获取条目,但我无法访问 getEntry() 中的值。

interface Example {
  contentTypeId: 'item'
  fields:{
   title: EntryFeildTypes.Text
   rate: EntryFeildTypes.Number
  }
}

interface Global {
 contentTypeId: 'product'
  fields:{
    title: EntryFeildTypes.Text
    point: EntryFeildTypes.EntryLink<Example>;
  }
}
const client = Contentful.createClient({...})
const data = await contentful.getEntry<Global>('product')

问题我无法通过做(data.fields.point。)访问率。

node.js typescript contentful
1个回答
0
投票

getEntry
函数接受一个条目 ID 并将返回该单个条目。如果要获取类型为
product
的所有条目,则必须使用
getEntry
函数。下面是一个例子:

client.getEntries({ content_type: 'product' }).then(e => console.log(e)).catch(e => console.error(e))

您可以在此处了解有关 SDK 的更多信息:https://contentful.github.io/contentful.js/contentful/10.1.3/interfaces/ContentfulClientApi.html#getEntry

希望这有帮助!

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