javascript更新tree节点的数据
var roots = [{ "children": [{ "children": [{ "children": [], "id": "4028806b6e7c25dd016e7cacbe78004c", "size": 0, "state": "open", "text": "标识厂区平面图、生产工艺流程和生产过程等方框示意图" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe68004b", "size": 0, "state": "open", "text": "企业概况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe680049", "size": 0, "state": "open", "text": "企业环保投资" } ], "id": "4028806b6e7c25dd016e7cacbddb0035", "size": 3, "state": "open", "text": "企业基本情况表支撑材料" }, { "children": [{ "children": [], "id": "4028806b6e7c25dd016e7cacbe68004a", "size": 0, "state": "open", "text": "执行环境影响评价资料" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe580047", "size": 0, "state": "open", "text": "执行环保“三同时”制度资料" } ], "id": "4028806b6e7c25dd016e7cacbddb0036", "size": 1, "state": "open", "text": "企业执行“环评”、“三同时”情况表支撑材料" }, { "children": [{ "children": [], "id": "4028806b6e7c25dd016e7cacbe580048", "size": 0, "state": "open", "text": "企业环保设施(装置)设计、建设资料" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe490045", "size": 0, "state": "open", "text": "一般工业固体废物排放量及综合利用" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe490046", "size": 0, "state": "open", "text": "工业危险废物产生及利用处置情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe390042", "size": 0, "state": "open", "text": "企业清洁生产审核情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe390043", "size": 0, "state": "open", "text": "企业内部监测情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe390044", "size": 0, "state": "open", "text": "排污口规范化建设情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe290040", "size": 0, "state": "open", "text": "企业总量控制情况" } ], "id": "4028806b6e7c25dd016e7cacbdcc0033", "size": 0, "state": "open", "text": "企业污染防治及总量控制情况表支撑材料" }, { "children": [{ "children": [], "id": "4028806b6e7c25dd016e7cacbe290041", "size": 0, "state": "open", "text": "排污许可证管理" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe1a003f", "size": 0, "state": "open", "text": "环境保护部门对企业的监察、监测" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe0a003d", "size": 0, "state": "open", "text": "污染物排放申报、排污费征收" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe0a003e", "size": 0, "state": "open", "text": "企业限期治理情况(限期治理企业)" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbdfb003b", "size": 0, "state": "open", "text": "信访投诉、环保行政处罚" } ], "id": "4028806b6e7c25dd016e7cacbdcc0034", "size": 0, "state": "open", "text": "环保部门对企业监督管理情况表支撑材料" }, { "children": [{ "children": [], "id": "4028806b6e7c25dd016e7cacbdfb003a", "size": 0, "state": "open", "text": "不符合国家有关政策要求的生产工艺、生产设施,实施淘汰、技改和关停计划明细及落实情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbe0a003c", "size": 0, "state": "open", "text": "企业环境管理机构、人员编制、培训和管理制度" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbdeb0038", "size": 0, "state": "open", "text": "企业防范环境突发事故措施和环境突发事故应急预案" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbdeb0039", "size": 0, "state": "open", "text": "环境保护设施运行情况" }, { "children": [], "id": "4028806b6e7c25dd016e7cacbdeb0037", "size": 0, "state": "open", "text": "企业环境信息公开" } ], "id": "4028806b6e7c25dd016e7cacbdbc0032", "size": 1, "state": "open", "text": "企业环境管理情况表支撑材料", "remind": 1 } ], "id": "4028806b6e7c25dd016e7cacbdbc0031", "size": 0, "state": "open", "text": "一企一档" }]; function setNode(nodes, parentNode) { if (nodes.length > 0) { for (var i = 0; i < nodes.length; i++) { if (!parentNode) { nodes[i].level = 0; } else { nodes[i].level = parentNode.level + 1; } // 模拟添加其他属性和数据 nodes[i].count = 1000; nodes[i].current = 500; if (nodes[i].children && nodes[i].children.length > 0) { setNode(nodes[i].children, nodes[i]); } } } } setNode(roots, null); console.log(JSON.stringify(roots, null, 4))