JSFiddle - React, Tailwind, and code Playground

by alekskorovin

HTML

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="mainCtrl">
        <select ng-model="selected" ng-change="update()">
            <option ng-repeat="option in tree" ng-bind-html-unsafe="option.displayName" value="{{$index}}">{{ option.displayName }}</option>
        </select>
    </div>
</div>

JavaScript

var app = angular.module('myApp', []);

app.controller("mainCtrl", function ($scope) {
    $scope.data = [{
        "id": 1,
            "name": "something1",
            "displayName": "something1",
            "children": [{
            "id": 9,
                "name": "something1Child1",
                "displayName": "something1/ something1Child1",
                "children": [{"id": 43,
                "name": "something1Child1Child1",
                "displayName": "something1Child1/ something1Child1Child1",
                "children": [],
                "typeId": 1,
                              "parentId": 9}],
                "typeId": 1,
                "parentId": 1
        }, {
            "id": 10,
                "name": "something1Child2",
                "displayName": "something1 / something1Child2",
                "children": [],
                "typeId": 1,
                "parentId": 1
        }]
    }, {
        "id": 2,
            "name": "something2",
            "displayName": "something2",
            "children": []
    }];
    
    $scope.tree = [];
    function buildTree(data, depth) {
        for(d in data) {
            var c = angular.copy(data[d]); //copy object
            delete c['children'];  //we dont want to copy children
            c.displayName = Array(depth*4).join("&nbsp;") + c.displayName;
            $scope.tree.push(c);
            buildTree(data[d].children, depth+1);
        }
    }
    buildTree($scope.data, 0);
    console.log($scope.tree);
    
    $scope.update = function() {
        console.log($scope.tree[$scope.selected]);
    }
});