Asset Manger not updating
Hi @awaredigital I can't see any issue on my side. If you open the Assets modal and run this code in the official demo you'll see it updating correctly So probably you'll need to create a reproducible demo with your case to see what is wrong
Read full answer below ↓Question
I've read the API and it says that we can filter assets by attributes. Cool! but I'm having trouble getting the asset manager to update:
I'm running the following:
editor.on('component:selected', component => {
const am = editor.AssetManager;
let assets = am.getAll().filter(
asset => asset.get('category') == 'cat-1'
);
console.log("Img in Cat-1: " + assets.length);
am.render(assets);
});
I have 2 images loading in my asset manager on editor.init -
grapesjs.init({
assetManager: {
assets: [
{category: "cat-0", src: "img.jpg", width: "x", height: "x"},
{category: "cat-1", src: "img.jpg", width: "x", height: "x"},
]
},
});
both images have the attribute:
category: 'cat-X'
I want to just load cat-1 but this just doesn't work. Console logging works fine and returns the item but the attribute manager doesn't. What am I doing wrong?
Thanks
Answers (1)
Hi @awaredigital I can't see any issue on my side. If you open the Assets modal and run this code in the official demo you'll see it updating correctly
const am = editor.AssetManager;
am.render(
am.getAll().filter(item => /image(1|2|3).jpg$/.test(item.get('src')))
);
So probably you'll need to create a reproducible demo with your case to see what is wrong
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3137
When I select an particular element I'm not getting its styles. This issue happens only with some elements.
Not getting styles of the selected element Here is my code, const model = editor.StyleManager.getModelToStyle(component); let styleObject =...
Issue #3135
[Help Wanted] How to easily override existing component ?
For example, I want to add a double click event handler on the default video component to open the assets manager. My basic idea was to get...
Issue #2705
[Question] Adding image sizes to image
When I add an image attribute to the page I noticed that inside of the component the image has attributes to it. When I call my images into...
Issue #2922
[QUESTION]: Get all css without specific component and it's children
Hi, so, in this issue #2861 we can get all the css of a selected element and it's children with: But if I want to get all the css but witho...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.
Browse premium plugins →Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.