Order Kontent.ai items by linkedItem element field.

huangapple go评论89阅读模式
英文:

Order Kontent.ai items by linkedItem element field

问题

I'm struggling to order items returned via the Kontent.ai delivery rest API using a field on the linked item of that piece of content.

My content model is as follows:

  • Web Page - contains generic information about a given web page e.g. metadata, url slug etc.
  • Page Template - contains the page data, posted date, content etc.

Each Web Page must have a Page Template as a linked item, and I ideally want to order all web pages on the linked page template posted date on list pages for example. But I can't seem to find anywhere in the docs to suggest this is possible.

Has anyone had any success with doing this?

Here is what my current orderByDescending call looks like:

orderByDescending("elements.page_template.linkedItems[0].elements.publication_date")

But this gives me an error.

英文:

I'm struggling to order items returned via the Kontent.ai delivery rest API using a field on the linked item of that piece of content.

My content model is as follows:

  • Web Page - contains generic information about a given web page e.g. metadata, url slug etc.
  • Page Template - contains the page data, posted date, content etc.

Each Web Page must have a Page Template as a linked item, and I ideally want to order all web pages on the linked page template posted date on list pages for example. But I can't seem to find anywhere in the docs to suggest this is possible.

Has anyone had any success with doing this?

Here is what my current orderByDescending call looks like:

orderByDescending("elements.page_template.linkedItems[0].elements.publication_date")

But this gives me an error.

答案1

得分: 3

很遗憾,无法根据链接项中嵌套的值在API级别或扩展SDK上进行订购或过滤,因为过滤方法只是API过滤操作的抽象。这与API响应的结构有关:

{
"items": [],
"modular_content": {},
"pagination": {}
}

在您的情况下,生成的项数组包含Web页面类型的项,它们仅保存对其各自模板项的代码名称引用。所有实际链接的项都存储在modular_content数组中,该数组是无序的。

唯一的方法是从API检索所有所需项,然后在您的代码中执行排序。

英文:

Unfortunately, It's not possible to order or filter based on values nested in linked items at the API level and by extension SDKs as the filtering methods are just abstractions of the API filtering operations. This has to do with the structure of the API response:

{
"items": [],
"modular_content": {},
"pagination": {}
}

In your case, the resulting items array contains the items of Web page type, which merely hold a codename reference to their respective Template items. All the actual linked items are stored in the modular_content array, which is unordered.

The only way to achieve this is to retrieve all required items from API and subsequently perform the ordering in your code.

huangapple
  • 本文由 发表于 2023年5月11日 16:39:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76225696.html
  • kentico-kontent
  • kontent-ai
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定