JSFiddle - React, Tailwind, and code Playground

by alim1990

JavaScript

var array = [];
function recursive(arr, dim_label, dim_name){
	
	for (prop in arr) {
    var title = arr["title"];
    if (prop == "children") {
    	var dim_name = "";
      var dim_label = "";
      var field_name = "";
      var field_label = "";
    	for (child in arr[prop]){
      	dim_name = arr[prop][child]["name"] +"/"+dim_name;
        type = arr[prop][child]["type"];
        field_name = dim_name+"/"+arr[prop][child]["name"];
        dim_label =arr[prop][child]["name"]["english"];
        field_label = "";
        if ("label" in arr[prop][child] ) {
         dim_label  = arr[prop][child]["label"]["english"];
         field_label = arr[prop][child]["label"]["english"]
        }
        else {
        	dim_label = dim_name;
        }
        array.push({label: dim_label, name: dim_name});
        if (type != "calculate" && type != "select one") {
        	if ("children" in arr[prop][child]) {
          	recursive(arr[prop][child], dim_label, dim_name);
          }
        }
        console.log(dim_name, dim_label, field_name, field_label)
      }
    }
  }
}


var arr = {
	"name": "data",
   "type": "survey",
   "title": "BGD_IYCFE_Daily_Report_v1",
   "children": [
        {
            "name": "start",
            "label": {
                "english": "start"
            },
            "type": "start"
        },
        {
            "name": "end",
            "label": {
                "english": "end"
            },
            "type": "end"
        },
        {
            "name": "today",
            "label": {
                "english": "Today"
            },
            "type": "today"
        },
        {
            "name": "deviceid",
            "label": {
                "english": "Deviceid"
            },
            "type": "deviceid"
        },
        {
            "name": "sector",
            "type": "calculate",
            "bind": {
                "calculate": "if(${campNo}!='','NUT','')"
            }
        },
        {
         ...