Issue #2743Opened April 28, 2020by andy-aware1 reactions

[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)

artfMay 4, 20201 reactions

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.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.