Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to use recursive function to select the parent in a tree array using angulat ui tree


function buildTree() {
    TreeService.getTree().then(function (result) {
        tc.tree = result.data;
        
        function setParentForChildren(n) {
            angular.forEach(n.children, function (c) {
                c.parent = n;
                setParentForChildren(c);
            })
        }
        angular.forEach(tc.tree, setParentForChildren);
    }, function (result) {
        alert("Tree no available, Error: " + result);
    });
}
Comment

how to use recursive function to select the parent in a tree array using angulat ui tree

$scope.checkNode = function (node) {
    node.checked = !node.checked;
    function checkParent(n) {
        if (!n.parent)
            return;
        const p = n.parent;
        p.checked = p.children.every(function(c) { return c.checked });
        checkParent(p);
    }
    
    checkParent(node);

    function checkChildren(c) {
        angular.forEach(c.children, function (c) {
            c.checked = node.checked;
            checkChildren(c);
        });
    }

    checkChildren(node);
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to merge array into JSON array 
Javascript :: Angular Nx Nrwl - Cannot parse tsconfig.base.json: PropertyNameExpected in JSON when try to create a new lib 
Javascript :: How to increase/decrease value with reducer 
Javascript :: How to pass React Native Component as a JSON object 
Javascript :: want the app to save the passing screen after a user has passed the test even when the app exits in react native 
Javascript :: Reanimated2 interpolateNode to animate opacity error "undefined is not an object 
Javascript :: react js graph with more than one y axis 
Javascript :: Scaling elements proportionally using CSS and JQUERY 
Javascript :: how to add link during filter and mapping in javascript 
Javascript :: sort lowest to highest js 
Javascript :: How to limit properties of a JSON object given array of property names using JQ 
Javascript :: Transfer file to server using rsync 
Javascript :: regex online converter 
Javascript :: javascript encriment +1 
Javascript :: Clear for me API jquery 
Javascript :: online convert javascript to typescript 
Javascript :: socket io inside route express not working 
Javascript :: vimscript replace function 
Javascript :: Staircase 
Javascript :: javascript download save files in folder 
Javascript :: react_devtools_backend.js:4026 Warning: Cannot update a component (`BrowserRouter`) while rendering a different component (`Login`). 
Javascript :: Function Written In Constructor Involving A Promise, Can Be Accessed As Below 
Javascript :: Hardhat config file multiple network 
Javascript :: JavaScript HTMLCollection Object 
Javascript :: problem with Next.js and @material-ui. 
Javascript :: connect nextjs to google sheets 
Javascript :: Backbone Router Notes 
Javascript :: Initialize View With Collection Backbone 
Javascript :: empty an array in javascript 
Javascript :: javascript filter array of object by id 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =