How to get the models trait of a component?
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)
simpler than I thought :)
editor.getSelected().defaults.traits
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.
Issue #3461
Re-render trait on selected component
I know there is a function that can rerender the view of a trait. However, I still don't know how and where to use it.
Issue #3228
Component Value is not changing
Hi @artf I've added a new component here is the code on selecting the h1 and h2 tag it's changing the value in the HTML section as you can...
Issue #3388
FEAT: adding indication as a Trait without any input.
I want to add an indication for a trait. For my component, I have the traits: and for the type 'dateformat-indication', I created the type:...
Issue #3233
Set Toolbar on every Component
Hi @artf Is there any standard way to add a new toolbar on every component I've tried this way When I run this code on the browser console...
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 →Related tutorials
In-depth guides on the same topic.
Tutorial
How to Build a Production GrapesJS Editor: The Complete Walkthrough of Brief, Preset, Plugins, and Services
A complete walkthrough of building a production GrapesJS editor: how to choose a preset, pick plugins, and scope setup services without burning a sprint.
Tutorial
Big Updates: TinyMCE 8 and Placeholder 2.0 for GrapesJS
In May we shipped major updates to two of our most popular GrapesJS plugins — TinyMCE Inline Text Editor and Placeholder.
Tutorial
Find the Right GrapesJS Plugin in Seconds: Smarter Discovery Is Live
We're shipping a set of discovery upgrades. New label filters, a proper compatibility switch for GrapesJS vs Studio, one-click and a smarter sort bar.
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.