Directus - 在另一个 collection 中创建或更新项目的示例挂钩
Directus - Example hook for creating or update an item in another collection
我正在构建一个具有列表视图的移动应用程序,该视图显示文章链接。该应用程序的内容由 Directus 提供支持。
列表视图有
title
description (200 characters, no HTML)
image
一篇文章有
title
content (html)
image
为了节省 API 请求的大小,我将列表视图数据存储在名为 articles_list
的 collection 中,将文章存储在名为 collection 的 articles
.
为了让 Directus 对作者直观,我需要 Directus 自动 create/update/delete articles_list
collection 中的一个项目,因为 created/updated/deleted articles
collection.
两个 collection 存储的数据基本相同,除了 articles_list
有 description
而不是 content
。在删除 HTML 标记后,description
字段具有 content
的前 200 个字符。
我看过 hooks 文档,但我不确定如何在不同的 collection (articles_list
) 中创建新项目。使用 ezyang/htmlpurifier 等外部库的最佳方式是什么?我该如何调试我的钩子?
如有任何帮助,我们将不胜感激。我仍在学习了解 Directus 的工作原理。
我建议创建一个包含 4 个字段的集合:
title
excerpt (/ description)
content (html)
image
然后您可以使用 fields
参数仅请求概览页面上的 title
和 excerpt
以节省一些带宽/延迟:
/items/articles?fields=title,excerpt
它还为您省去了必须保持两个集合同步的麻烦,并且避免了必须存储重复数据
这是一个钩子内部调试的例子
你的问题在这里,如果你想从 hook 更改另一个集合字段,更好的方法是使用 ZendDB Example filter hook to update item with related field
我正在构建一个具有列表视图的移动应用程序,该视图显示文章链接。该应用程序的内容由 Directus 提供支持。
列表视图有
title
description (200 characters, no HTML)
image
一篇文章有
title
content (html)
image
为了节省 API 请求的大小,我将列表视图数据存储在名为 articles_list
的 collection 中,将文章存储在名为 collection 的 articles
.
为了让 Directus 对作者直观,我需要 Directus 自动 create/update/delete articles_list
collection 中的一个项目,因为 created/updated/deleted articles
collection.
两个 collection 存储的数据基本相同,除了 articles_list
有 description
而不是 content
。在删除 HTML 标记后,description
字段具有 content
的前 200 个字符。
我看过 hooks 文档,但我不确定如何在不同的 collection (articles_list
) 中创建新项目。使用 ezyang/htmlpurifier 等外部库的最佳方式是什么?我该如何调试我的钩子?
如有任何帮助,我们将不胜感激。我仍在学习了解 Directus 的工作原理。
我建议创建一个包含 4 个字段的集合:
title
excerpt (/ description)
content (html)
image
然后您可以使用 fields
参数仅请求概览页面上的 title
和 excerpt
以节省一些带宽/延迟:
/items/articles?fields=title,excerpt
它还为您省去了必须保持两个集合同步的麻烦,并且避免了必须存储重复数据
这是一个钩子内部调试的例子
你的问题在这里,如果你想从 hook 更改另一个集合字段,更好的方法是使用 ZendDB Example filter hook to update item with related field