tree 树结构 自己组装数据

easyUI组装两级树结构 

这是组装的方式:

{
    "open": [
        {
            "id": 46,
            "pName": "天天速冻间",
            "pPyName": "TTSDJ",
            "pNumber": "DS202009280046",
            "pCode": "0046",
            "projectendflag": "0",  
            "creattime": "2020-09-28 09:48:23",
            "pcategoryName": "",
            "isOpenWarehouse": "0"
        },
        {
            "id": 47,
            "pName": "天天面食",
            "pPyName": "TTMS",
            "pNumber": "DS202009280047",
            "pCode": "0047",
            "projectendflag": "0",
            "creattime": "2020-09-28 09:48:23",
            "pcategoryName": "",
            "isOpenWarehouse": "0"
        }
    ],
    "close": [
        {
            "id": 38,
            "pName": "武汉万吨",
            "pPyName": "WHWD,WHMD",
            "pNumber": "DS202009270001",
            "pCode": "0001",
            "projectendflag": "1",
            "creattime": "2020-09-27 12:01:00",
            "pcategoryName": "",
            "isOpenWarehouse": "0"
        }
    ]
}

返回的JSON格式

$.get("请求接口", function(data) {
		let date_da = data.result; //返回json串
		let openData = []; //tree用到的数组
		let open = []; //开始的项目
		let open_da = {}; //tree最外层的对象
		let opendachil = []; //tree最外层的数组
		for (let j = 0; j < date_da.open.length; j++) { //循环开始的项目放入对象中
			let open_da_children = {}; //easyUI tree  json串最里面的对象
			open_da_children.id = date_da.open[j].id; //获取id
			open_da_children.text = date_da.open[j].pName; //获取pName
			opendachil.push(open_da_children); //对象放入数组中 
		}
		open_da.text = "施工项目"; //tree一级
		open_da.children = opendachil; //tree第二级放入一级children
		openData.push(open_da) //tree 一级对象放入json数组中
		
		let close = [];
		let close_da = {};
		let closedachil = [];
		for (let i = 0; i < date_da.close.length; i++) {
			let close_da_children = {};
			close_da_children.id = date_da.close[i].id;
			close_da_children.text = date_da.close[i].pName;
			closedachil.push(close_da_children);
		}
		close_da.text = "竣工项目";
		close_da.children = closedachil;
		openData.push(close_da)
		$("#tree_wl").tree({data: openData}) //展示tree的json串
	})

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值