Untitled

mail@pastecode.io avatar
unknown
plain_text
13 days ago
1.9 kB
3
Indexable
Never
$('#treeContainer').simpleTree({
                        data: data // assuming response is already in the correct format
                    });

                    // Use MutationObserver to detect when .simpleTree-label elements are rendered
                    const observer = new MutationObserver(function(mutationsList, observer) {
                        // Check for the presence of .simpleTree-label
                        if ($('.simpleTree-label').length > 0) {
                            console.log("Tree labels detected!");

                            // Apply your logic based on the original response data
                            data.forEach(element => {
                                let node = $('.simpleTree-label').filter(function() {
                                    return $(this).text().trim() === element.label; // Ensure this matches your data structure
                                });

                                // Apply colors based on sparse_status
                                if (node.length) {
                                    if (element.sparse_status === 1) {
                                        node.addClass('green-node');
                                    } else {
                                        node.addClass('red-node');
                                    }
                                }
                            });

                            // Disconnect the observer after coloring
                            observer.disconnect();
                        }
                    });

                    // Start observing the tree container for changes (when new nodes are added)
                    observer.observe(document.getElementById('treeContainer'), {
                        childList: true,  // Detect when child elements are added
                        subtree: true     // Monitor the subtree of treeContainer
                    });
Leave a Comment