Issue #2991Opened September 2, 2020by Abhisheknanda13444633 reactions

Editor.getSelected() giving me undefined.

Question

Hi @artf I want to append dynamic pages to the specific link trait. Here is what i am using. const component = editor.getSelected(); component.getTrait('link').set('options', [ { value: 'opt1', name: 'New option 1'}, { value: 'opt2', name: 'New option 2'}, ]); This is giving component is undefined in the console because by default not any element is selected Could you please guide me on this . I want to append that pages in list of link trait whenever i click on the link

Answers (3)

Ju99ernautSeptember 5, 20202 reactions

You can check if component.getTrait('href') gets anything first:

editor.on('component:selected', component => {
   component.getTrait('href') && component.getTrait('href').set('options', data.list);
});
Abhisheknanda1344463September 6, 20201 reactions

Thank you so much @Ju99ernaut Now,It working perfectly. Really appreciate your help. Closing this issue.

Ju99ernautSeptember 5, 20200 reactions

You can add that to each component type using:

const components = editor.Components.getTypes();
components.forEach(component => {
    //manipulate traits here...
});

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.