I have a tree with Node object:
class Node implements ITreeNode { id?: any; name: string; children:? Node[], enabledState = new Subject<boolean>(); toggle() { this.enabled = !this.enabled; this.enabledState.next(this.enabled); } }
I want to know how much Nodes were enabled(selected). After each selection I push state. But how to count all enabled nodes in the tree? I think it is bad to idea to subscribe to all nodes.
What it′s "ITreeNode" in your code?
You can do something similar to this code:
public getEnableds(): number { let count = this.enabled ? 1 : 0; this.children(s).map(x => count += x.getEnableds()); return count; }
2.1m questions
2.1m answers
60 comments
57.0k users