Issue #3185💬 AnsweredOpened December 11, 2020by Stiggi0 reactions

How to get the models trait of a component?

Quick answerby Stiggi

simpler than I thought :) editor.getSelected().defaults.traits

Read full answer below ↓

Question

Hi there,

I added a new type "array" to the TraitManager. So I can add several sub traits. On one point I have to check the traits of the model. I do this with a construct like this:

domc = editor.DomComponents;
selc = editor.getSelected();  // get the currently selected component

type = selc.get('type'); // now i have the type name of my selected component

comType = domc.getType( type );
defaultTraits = comType.model.prototype.defaults.traits;

Is there an easier way to get the model of a component directly from the component?

Best regards, Michael

Answers (2)

StiggiDecember 16, 2020

simpler than I thought :)

editor.getSelected().defaults.traits

GJSBlockMay 17, 2026

Thanks for reporting this, @Stiggi. Great question about [QUESTION] How to get the models trait of a component?. The recommended approach with Components is to use the event-driven API. Start here: Check the GrapesJS documentation for your specific module Look for the on() event listener method Mos...

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.