angular.js - How to write recursion in JS or angular?
怪我咯
怪我咯 2017-05-15 17:04:23
0
1
551

The picture shown is an object. Each child node has an array of children. The arrays are all combinations of objects in this pattern.

The lowest children.length=0. I need to add objects to a collection according to the nodes in sequence, such as angular's $scope.list=[];

This is what I write now. It works, but the order is wrong. Some nodes are later, but earlier, so the display is wrong:

cycle(data);


        function cycle(projection) {
            console.log("现在第几:"+times,projection.name);
            times += 1;
            if(times < 15) {

                for(var k in projection) {

                    if(k == "children") {

//                        console.log("find k.value is:", projection[k]);

                        if(projection[k].length > 0) {

                            for(var i = 0; i < projection[k].length; i++) {

//                                console.log("size>0:name", projection[k][i].name, projection[k][i]);

                                cycle(projection[k][i]);

                                $scope.dd.push(projection[k][i]);
                            }
                        }
                    }
                }
            } 
        }

        console.log("sfdsfsdfsdfsdf:", $scope.dd);
    });

The requirement is: the nodes of the pyramid must be added to $scope.list.push() in sequence, and the node objects of the third layer cannot be added to it before the objects of the second layer. How to improve this stuff?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
習慣沉默

Eliminate zero reply grass grass grass grass grass grass grass grass grass grass grass

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template