Question: how to observe children changes in component
Question
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type? Perhaps an event I can subscribe to? Something like change:content?
I want to add traits to children of my container component. If the children leave the container, the traits should disappear.
I can think of 1 workaround. Something like:
// in the view
this.el.bind("DOMSubtreeModified",function(){
alert('changed');
});
Answers (3)
Is there an easy way to subscribe/listen to changes in the components/children of my custom component type?
@scottccoates you can subscribe this way:
init(){ // inside your model
this.listenTo(this.components().at(0),'change:prop-name', handler)
}
cheers!
@pouyamiralayi thanks. I need to watch for children leaving/entering my component. I'm not sure what you supplied will help or am I missing something?
@scottccoates this might help:
editor.on('component:add', model => console.log(model.parent().get('custom-name')))
editor.on('component:remove', model => console.log(model.parent().get('custom-name')))
cheers!
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2193
[QUESTION] Reset trait on edit the content of a custom component
Hi, I have a custom component which content can be changed by switching trait select options, but also can be edited similar to the text co...
Issue #3019
[QUESTION] - Bind inner text/html (like div, p, h1) to Trait
Hi! I've created a custom trait, and I want to be allowed to change the content of the tags (in this case it's a H1 tag) based on the trait...
Issue #2933
QUESTION: Is there a way to listen to class name changes
I have created a added a component to the "view". I want to show this component only in view (and not add to model/html thus added to the v...
Issue #2012
[question] how to add script for all widgets(like protectedCss)
I want to add some functions for all components accessible. when initialize editor, there is a option like protectedCss. Isn't there a way...
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.