英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论