日期:2014-05-16  浏览次数:20555 次

递归 删除json tree 结构 无用字段
var test =  {
	"text" : "任务组3",
	"nodeType" : "任务组",
	"tabid" : "procedure_one",
	"children" : [{
			"text" : "新任务1",
			"nodeType" : "任务",
			"tabid" : "procedure_one",
			"treedataindex" : 4,
			"__status" : "add"
		}, {
			"text" : "新任务2",
			"nodeType" : "任务",
			"tabid" : "procedure_one",
			"children" : [{
					"text" : "新条件",
					"nodeType" : "条件",
					"tabid" : "procedure_one",
					"treedataindex" : 6,
					"__status" : "add"
				}, {
					"text" : "新条件1",
					"nodeType" : "条件",
					"tabid" : "procedure_one",
					"children" : [{
							"text" : "新工单请求",
							"tabid" : "procedure_one",
							"treedataindex" : 8,
							"__status" : "add"
						}, {
							"text" : "新跳跃",
							"tabid" : "procedure_one",
							"treedataindex" : 9,
							"__status" : "add"
						}, {
							"text" : "决策",
							"nodeType" : "决策",
							"tabid" : "procedure_one",
							"treedataindex" : 10,
							"__status" : "add"
						}, {
							"text" : "任务组1",
							"nodeType" : "任务组",
							"tabid" : "procedure_one",
							"treedataindex" : 11,
							"__status" : "add"
						}
					],
					"treedataindex" : 7,
					"__status" : "add"
				}, {
					"text" : "test",
					"tabid" : "procedure_one",
					"treedataindex" : 12,
					"__status" : "add"
				}
			],
			"treedataindex" : 5,
			"__status" : "add"
		}
	],
	"treedataindex" : 3,
	"__status" : "add"
}



function removeAttr(node){
        delete node['treedataindex'];
        delete node['__status'];
        var children = node.children;
        if (children)
        {
            $.each(children, function ()
            {
                removeAttr(this);
            });
        }
}



{
	"text" : "任务组3",
	"nodeType" : "任务组",
	"tabid" : "procedure_one",
	"children" : [{
			"text" : "新任务1",
			"nodeType" : "任务",
			"tabid" : "procedure_one"
		}, {
			"text" : "新任务2",
			"nodeType" : "任务",
			"tabid" : "procedure_one",
			"children" : [{
					"text" : "新条件",
					"nodeType" : "条件",
					"tabid" : "procedure_one"
				}, {
					"text" : "新条件1",
					"nodeType" : "条件",
					"tabid" : "procedure_one",
					"children" : [{
							"text" : "新工单请求",
							"tabid" : "procedure_one"
						}, {
							"text" : "新跳跃",
							"tabid" : "procedure_one"
						}, {
							"text" : "决策",
							"nodeType" : "决策",
							"tabid" : "procedure_one"
						}, {
							"text" : "任务组1",
							"nodeType" : "任务组",
							"tabid" : "procedure_one"
						}
					]
				}, {
					"text" : "test",
					"tabid" : "procedure_one"
				}
			]
		}
	]
}