QUESTION: How to save the dynamically added traits
Question
Hi, @artf, I have a custom component that has a button trait. When the button is pressed, I am adding a custom trait dynamically using comp.addTrait().
When I load the saved template, I want the container to show the dynamically added traits too. (I am loading the template using components but the dynamically added traits are not being shown). What might I be doing wrong?
Answers (3)
I made it work by having a count attribute on the component and then adding the trait count times in the init of the container.
This is the correct way.
Traits are intentionally skipped from the JSON, otherwise, you'd put on hold your component definition in the storage (eg. the day you'll upgrade the component with new traits, your users will still see the old ones)
@artf, thanks for replying. That was a really valuable piece of information.
I made it work by having a count attribute on the component and then adding the trait count times in the init of the container.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2404
Question: how to observe children changes in component
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type? Perhaps an event I can subscrib...
Issue #2136
[QUESTION] custom component type not found and traits not working after page load
Hi @artf I have created a very basic custom component named 'customsection' which uses traits to change the component's background-color by...
Issue #3052
BUG: hide/show traits and change their values dynamically
I have extended the link component and add new traits like href. In order to show or hide the trait i followed this #https://github.com/art...
Issue #3111
Question: How to trigger something (function) on adding asset?
Hi, @artf. What is the correct way to trigger a function when an asset is added to the assets by providing the link and then pressing the '...
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.