通过使用下面建议的补丁,数据字段似乎填充正常,但是,媒体字段未填充。
尝试了以下但没有运气 -
* http://localhost:1337/api/pages?populate=*
* {{protocol}}://{{host}}:{{port}}/api/pages?populate[Content][populate]=images
Run Code Online (Sandbox Code Playgroud)
下面的示例来自 - 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)