[Question] Asset Manger not updating
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 #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...
Issue #2819
[Question] I am updating trait using addTrait function? It updates and adds the trait in trait manager but unable to reflect it in html section of codeManager?
I have written the following code - const component = editor.getSelected(); component.addTrait({ name: 'traitName', type: 'text', label: 't...
Issue #930
[Question] Update resizer after asset changed
Hi! I trying to change default assets manager with ours custom manager. On double click the selected image is replaced with a new one with...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.