相关疑难解决方法(0)

Strapi V4 填充动态区域 媒体未填充

通过使用下面建议的补丁,数据字段似乎填充正常,但是,媒体字段未填充。

尝试了以下但没有运气 -

* http://localhost:1337/api/pages?populate=*
* {{protocol}}://{{host}}:{{port}}/api/pages?populate[Content][populate]=images
Run Code Online (Sandbox Code Playgroud)

参考 - https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/rest/populate-fields.html#component-dynamic-zones

下面的示例来自 - https://forum.strapi.io/t/strapi-v4-populate-media-and-dynamiczones-from-components/12670/9

还尝试了这个插件(没有运气) - https://www.npmjs.com/package/strapi-plugin-populate-deep

下面带有动态区域的页面示例 -

在此输入图像描述

/helpers/populate.js(这适用于除图像之外的所有数据)-

const { createCoreController } = require("@strapi/strapi/lib/factories");

function populateAttribute({ components }) {
  if (components) {
    const populate = components.reduce((currentValue, current) => {
      return { ...currentValue, [current.split(".").pop()]: { populate: "*" } };
    }, {});
    return { populate };
  }
  return { populate: "*" };
}

const getPopulateFromSchema = function (schema) {
  return Object.keys(schema.attributes).reduce((currentValue, current) => {
    const attribute = schema.attributes[current];
    if (!["dynamiczone", "component"].includes(attribute.type)) …
Run Code Online (Sandbox Code Playgroud)

controller strapi

11
推荐指数
2
解决办法
1万
查看次数

标签 统计

controller ×1

strapi ×1